Skip to content

Commit dc2ce60

Browse files
authored
[mlir][CAPI] Add mlirOpOperandGetValue (#75032)
1 parent 3764f5e commit dc2ce60

File tree

3 files changed

+16
-0
lines changed

3 files changed

+16
-0
lines changed

mlir/include/mlir-c/IR.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -940,6 +940,9 @@ MLIR_CAPI_EXPORTED void mlirValueReplaceAllUsesOfWith(MlirValue of,
940940
/// Returns whether the op operand is null.
941941
MLIR_CAPI_EXPORTED bool mlirOpOperandIsNull(MlirOpOperand opOperand);
942942

943+
/// Returns the value of an op operand.
944+
MLIR_CAPI_EXPORTED MlirValue mlirOpOperandGetValue(MlirOpOperand opOperand);
945+
943946
/// Returns the owner operation of an op operand.
944947
MLIR_CAPI_EXPORTED MlirOperation mlirOpOperandGetOwner(MlirOpOperand opOperand);
945948

mlir/lib/CAPI/IR/IR.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -986,6 +986,10 @@ MlirOperation mlirOpOperandGetOwner(MlirOpOperand opOperand) {
986986
return wrap(unwrap(opOperand)->getOwner());
987987
}
988988

989+
MlirValue mlirOpOperandGetValue(MlirOpOperand opOperand) {
990+
return wrap(unwrap(opOperand)->get());
991+
}
992+
989993
unsigned mlirOpOperandGetOperandNumber(MlirOpOperand opOperand) {
990994
return unwrap(opOperand)->getOperandNumber();
991995
}

mlir/test/CAPI/ir.c

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1970,6 +1970,15 @@ int testOperands(void) {
19701970
fprintf(stderr, "\n");
19711971
// CHECK: Second replacement use owner: "dummy.op2"
19721972

1973+
MlirOpOperand use5 = mlirValueGetFirstUse(constTwoValue);
1974+
MlirOpOperand use6 = mlirOpOperandGetNextUse(use5);
1975+
if (!mlirValueEqual(mlirOpOperandGetValue(use5),
1976+
mlirOpOperandGetValue(use6))) {
1977+
fprintf(stderr,
1978+
"ERROR: First and second operand should share the same value\n");
1979+
return 5;
1980+
}
1981+
19731982
mlirOperationDestroy(op);
19741983
mlirOperationDestroy(op2);
19751984
mlirOperationDestroy(constZero);

0 commit comments

Comments
 (0)