aboutsummaryrefslogtreecommitdiff
path: root/mlir/test/CAPI/ir.c
diff options
context:
space:
mode:
authormax <maksim.levental@gmail.com>2023-04-26 09:55:27 -0500
committermax <maksim.levental@gmail.com>2023-04-26 14:04:33 -0500
commit5b303f21d38b211341537b94a4783ed9975d6bb1 (patch)
tree0834f6ef9ac43325a2875c88e1431f5f01ad93bb /mlir/test/CAPI/ir.c
parent951919e5112cabbd63c7a3bf424736efca81d964 (diff)
downloadllvm-5b303f21d38b211341537b94a4783ed9975d6bb1.zip
llvm-5b303f21d38b211341537b94a4783ed9975d6bb1.tar.gz
llvm-5b303f21d38b211341537b94a4783ed9975d6bb1.tar.bz2
[MLIR][python bindings] Reimplement `replace_all_uses_with` on `PyValue`
Differential Revision: https://reviews.llvm.org/D149261
Diffstat (limited to 'mlir/test/CAPI/ir.c')
-rw-r--r--mlir/test/CAPI/ir.c52
1 files changed, 52 insertions, 0 deletions
diff --git a/mlir/test/CAPI/ir.c b/mlir/test/CAPI/ir.c
index 5f205c4..ca2e036 100644
--- a/mlir/test/CAPI/ir.c
+++ b/mlir/test/CAPI/ir.c
@@ -1873,9 +1873,61 @@ int testOperands(void) {
return 3;
}
+ MlirOperationState op2State =
+ mlirOperationStateGet(mlirStringRefCreateFromCString("dummy.op2"), loc);
+ MlirValue initialOperands2[] = {constOneValue};
+ mlirOperationStateAddOperands(&op2State, 1, initialOperands2);
+ MlirOperation op2 = mlirOperationCreate(&op2State);
+
+ MlirOpOperand use3 = mlirValueGetFirstUse(constOneValue);
+ fprintf(stderr, "First use owner: ");
+ mlirOperationPrint(mlirOpOperandGetOwner(use3), printToStderr, NULL);
+ fprintf(stderr, "\n");
+ // CHECK: First use owner: "dummy.op2"
+
+ use3 = mlirOpOperandGetNextUse(mlirValueGetFirstUse(constOneValue));
+ fprintf(stderr, "Second use owner: ");
+ mlirOperationPrint(mlirOpOperandGetOwner(use3), printToStderr, NULL);
+ fprintf(stderr, "\n");
+ // CHECK: Second use owner: "dummy.op"
+
+ MlirAttribute indexTwoLiteral =
+ mlirAttributeParseGet(ctx, mlirStringRefCreateFromCString("2 : index"));
+ MlirNamedAttribute indexTwoValueAttr = mlirNamedAttributeGet(
+ mlirIdentifierGet(ctx, mlirStringRefCreateFromCString("value")),
+ indexTwoLiteral);
+ MlirOperationState constTwoState = mlirOperationStateGet(
+ mlirStringRefCreateFromCString("arith.constant"), loc);
+ mlirOperationStateAddResults(&constTwoState, 1, &indexType);
+ mlirOperationStateAddAttributes(&constTwoState, 1, &indexTwoValueAttr);
+ MlirOperation constTwo = mlirOperationCreate(&constTwoState);
+ MlirValue constTwoValue = mlirOperationGetResult(constTwo, 0);
+
+ mlirValueReplaceAllUsesOfWith(constOneValue, constTwoValue);
+
+ use3 = mlirValueGetFirstUse(constOneValue);
+ if (!mlirOpOperandIsNull(use3)) {
+ fprintf(stderr, "ERROR: Use should be null\n");
+ return 4;
+ }
+
+ MlirOpOperand use4 = mlirValueGetFirstUse(constTwoValue);
+ fprintf(stderr, "First replacement use owner: ");
+ mlirOperationPrint(mlirOpOperandGetOwner(use4), printToStderr, NULL);
+ fprintf(stderr, "\n");
+ // CHECK: First replacement use owner: "dummy.op"
+
+ use4 = mlirOpOperandGetNextUse(mlirValueGetFirstUse(constTwoValue));
+ fprintf(stderr, "Second replacement use owner: ");
+ mlirOperationPrint(mlirOpOperandGetOwner(use4), printToStderr, NULL);
+ fprintf(stderr, "\n");
+ // CHECK: Second replacement use owner: "dummy.op2"
+
mlirOperationDestroy(op);
+ mlirOperationDestroy(op2);
mlirOperationDestroy(constZero);
mlirOperationDestroy(constOne);
+ mlirOperationDestroy(constTwo);
mlirContextDestroy(ctx);
return 0;