MLIR_CAPI_EXPORTED bool mlirOperationEqual(MlirOperation op,
MlirOperation other);
+/// Gets the context this operation is associated with
+MLIR_CAPI_EXPORTED MlirContext mlirOperationGetContext(MlirOperation op);
+
/// Gets the name of the operation as an identifier.
MLIR_CAPI_EXPORTED MlirIdentifier mlirOperationGetName(MlirOperation op);
/// perform deep comparison.
MLIR_CAPI_EXPORTED bool mlirBlockEqual(MlirBlock block, MlirBlock other);
+/// Returns the closest surrounding operation that contains this block.
+MLIR_CAPI_EXPORTED MlirOperation mlirBlockGetParentOperation(MlirBlock);
+
/// Returns the block immediately following the given block in its parent
/// region.
MLIR_CAPI_EXPORTED MlirBlock mlirBlockGetNextInRegion(MlirBlock block);
return unwrap(op) == unwrap(other);
}
+MlirContext mlirOperationGetContext(MlirOperation op) {
+ return wrap(unwrap(op)->getContext());
+}
+
MlirIdentifier mlirOperationGetName(MlirOperation op) {
return wrap(unwrap(op)->getName().getIdentifier());
}
return unwrap(block) == unwrap(other);
}
+MlirOperation mlirBlockGetParentOperation(MlirBlock block) {
+ return wrap(unwrap(block)->getParentOp());
+}
+
MlirBlock mlirBlockGetNextInRegion(MlirBlock block) {
return wrap(unwrap(block)->getNextNode());
}
return 0;
}
+/// Tests backreference APIs
+static int testBackreferences() {
+ fprintf(stderr, "@test_backreferences\n");
+
+ MlirContext ctx = mlirContextCreate();
+ mlirContextSetAllowUnregisteredDialects(ctx, true);
+ MlirLocation loc = mlirLocationUnknownGet(ctx);
+
+ MlirOperationState opState = mlirOperationStateGet(mlirStringRefCreateFromCString("invalid.op"), loc);
+ MlirRegion region = mlirRegionCreate();
+ MlirBlock block = mlirBlockCreate(0, NULL);
+ mlirRegionAppendOwnedBlock(region, block);
+ mlirOperationStateAddOwnedRegions(&opState, 1, ®ion);
+ MlirOperation op = mlirOperationCreate(&opState);
+
+ if (!mlirContextEqual(ctx, mlirOperationGetContext(op))) {
+ fprintf(stderr, "ERROR: Getting context from operation failed\n");
+ return 1;
+ }
+ if (!mlirOperationEqual(op, mlirBlockGetParentOperation(block))) {
+ fprintf(stderr, "ERROR: Getting parent operation from block failed\n");
+ return 2;
+ }
+
+ mlirOperationDestroy(op);
+ mlirContextDestroy(ctx);
+
+ // CHECK-LABEL: @test_backreferences
+ return 0;
+}
+
// Wraps a diagnostic into additional text we can match against.
MlirLogicalResult errorHandler(MlirDiagnostic diagnostic, void *userData) {
fprintf(stderr, "processing diagnostic (userData: %ld) <<\n", (long)userData);
return 8;
if (registerOnlyStd())
return 9;
+ if (testBackreferences())
+ return 10;
mlirContextDestroy(ctx);