[Mlir-commits] [mlir] 6962bd6 - [MLIR] Add context accessor to identifier
llvmlistbot at llvm.org
llvmlistbot at llvm.org
Tue Feb 9 13:22:16 PST 2021
Author: George
Date: 2021-02-09T13:21:30-08:00
New Revision: 6962bd68f15d2fc43304166f55996c9dfa31bfd4
URL: https://github.com/llvm/llvm-project/commit/6962bd68f15d2fc43304166f55996c9dfa31bfd4
DIFF: https://github.com/llvm/llvm-project/commit/6962bd68f15d2fc43304166f55996c9dfa31bfd4.diff
LOG: [MLIR] Add context accessor to identifier
I knew I would miss one...
Reviewed By: stellaraccident
Differential Revision: https://reviews.llvm.org/D96321
Added:
Modified:
mlir/include/mlir-c/IR.h
mlir/lib/CAPI/IR/IR.cpp
mlir/test/CAPI/ir.c
Removed:
################################################################################
diff --git a/mlir/include/mlir-c/IR.h b/mlir/include/mlir-c/IR.h
index 65c097a7604e..d807cd46dd58 100644
--- a/mlir/include/mlir-c/IR.h
+++ b/mlir/include/mlir-c/IR.h
@@ -641,6 +641,9 @@ MLIR_CAPI_EXPORTED MlirNamedAttribute mlirNamedAttributeGet(MlirIdentifier name,
MLIR_CAPI_EXPORTED MlirIdentifier mlirIdentifierGet(MlirContext context,
MlirStringRef str);
+/// Returns the context associated with this identifier
+MLIR_CAPI_EXPORTED MlirContext mlirIdentifierGetContext(MlirIdentifier);
+
/// Checks whether two identifiers are the same.
MLIR_CAPI_EXPORTED bool mlirIdentifierEqual(MlirIdentifier ident,
MlirIdentifier other);
diff --git a/mlir/lib/CAPI/IR/IR.cpp b/mlir/lib/CAPI/IR/IR.cpp
index ba4a985aef45..fc66b8b5b7c4 100644
--- a/mlir/lib/CAPI/IR/IR.cpp
+++ b/mlir/lib/CAPI/IR/IR.cpp
@@ -661,6 +661,10 @@ MlirIdentifier mlirIdentifierGet(MlirContext context, MlirStringRef str) {
return wrap(Identifier::get(unwrap(str), unwrap(context)));
}
+MlirContext mlirIdentifierGetContext(MlirIdentifier ident) {
+ return wrap(unwrap(ident).getContext());
+}
+
bool mlirIdentifierEqual(MlirIdentifier ident, MlirIdentifier other) {
return unwrap(ident) == unwrap(other);
}
diff --git a/mlir/test/CAPI/ir.c b/mlir/test/CAPI/ir.c
index 7576133e60d4..8b785ee897bb 100644
--- a/mlir/test/CAPI/ir.c
+++ b/mlir/test/CAPI/ir.c
@@ -1456,6 +1456,7 @@ static int testBackreferences() {
mlirRegionAppendOwnedBlock(region, block);
mlirOperationStateAddOwnedRegions(&opState, 1, ®ion);
MlirOperation op = mlirOperationCreate(&opState);
+ MlirIdentifier ident = mlirIdentifierGet(ctx, mlirStringRefCreateFromCString("identifier"));
if (!mlirContextEqual(ctx, mlirOperationGetContext(op))) {
fprintf(stderr, "ERROR: Getting context from operation failed\n");
@@ -1465,6 +1466,10 @@ static int testBackreferences() {
fprintf(stderr, "ERROR: Getting parent operation from block failed\n");
return 2;
}
+ if (!mlirContextEqual(ctx, mlirIdentifierGetContext(ident))) {
+ fprintf(stderr, "ERROR: Getting context from identifier failed\n");
+ return 3;
+ }
mlirOperationDestroy(op);
mlirContextDestroy(ctx);
More information about the Mlir-commits
mailing list