[Mlir-commits] [mlir] f9f708e - [mlir][CAPI] Allow specifying pass manager anchor
llvmlistbot at llvm.org
llvmlistbot at llvm.org
Thu Oct 27 10:32:19 PDT 2022
Author: rkayaith
Date: 2022-10-27T13:32:14-04:00
New Revision: f9f708ef41233bdc330cd8c6f82f48a1f5c962b0
URL: https://github.com/llvm/llvm-project/commit/f9f708ef41233bdc330cd8c6f82f48a1f5c962b0
DIFF: https://github.com/llvm/llvm-project/commit/f9f708ef41233bdc330cd8c6f82f48a1f5c962b0.diff
LOG: [mlir][CAPI] Allow specifying pass manager anchor
This adds a new function for creating pass managers that takes an
argument for the anchor string.
Reviewed By: mehdi_amini
Differential Revision: https://reviews.llvm.org/D136404
Added:
Modified:
mlir/include/mlir-c/Pass.h
mlir/lib/CAPI/IR/Pass.cpp
mlir/test/CAPI/pass.c
Removed:
################################################################################
diff --git a/mlir/include/mlir-c/Pass.h b/mlir/include/mlir-c/Pass.h
index 6f281b6dc7aa1..704121a0cb096 100644
--- a/mlir/include/mlir-c/Pass.h
+++ b/mlir/include/mlir-c/Pass.h
@@ -51,9 +51,13 @@ DEFINE_C_API_STRUCT(MlirOpPassManager, void);
// PassManager/OpPassManager APIs.
//===----------------------------------------------------------------------===//
-/// Create a new top-level PassManager.
+/// Create a new top-level PassManager with the default anchor.
MLIR_CAPI_EXPORTED MlirPassManager mlirPassManagerCreate(MlirContext ctx);
+/// Create a new top-level PassManager anchored on `anchorOp`.
+MLIR_CAPI_EXPORTED MlirPassManager
+mlirPassManagerCreateOnOperation(MlirContext ctx, MlirStringRef anchorOp);
+
/// Destroy the provided PassManager.
MLIR_CAPI_EXPORTED void mlirPassManagerDestroy(MlirPassManager passManager);
diff --git a/mlir/lib/CAPI/IR/Pass.cpp b/mlir/lib/CAPI/IR/Pass.cpp
index 398abfee2ba1b..30f5804876940 100644
--- a/mlir/lib/CAPI/IR/Pass.cpp
+++ b/mlir/lib/CAPI/IR/Pass.cpp
@@ -24,6 +24,11 @@ MlirPassManager mlirPassManagerCreate(MlirContext ctx) {
return wrap(new PassManager(unwrap(ctx)));
}
+MlirPassManager mlirPassManagerCreateOnOperation(MlirContext ctx,
+ MlirStringRef anchorOp) {
+ return wrap(new PassManager(unwrap(ctx), unwrap(anchorOp)));
+}
+
void mlirPassManagerDestroy(MlirPassManager passManager) {
delete unwrap(passManager);
}
diff --git a/mlir/test/CAPI/pass.c b/mlir/test/CAPI/pass.c
index 966bcaf8caeac..5b04d749b1cdc 100644
--- a/mlir/test/CAPI/pass.c
+++ b/mlir/test/CAPI/pass.c
@@ -140,7 +140,8 @@ static void dontPrint(MlirStringRef str, void *userData) {
void testPrintPassPipeline() {
MlirContext ctx = mlirContextCreate();
- MlirPassManager pm = mlirPassManagerCreate(ctx);
+ MlirPassManager pm = mlirPassManagerCreateOnOperation(
+ ctx, mlirStringRefCreateFromCString("any"));
// Populate the pass-manager
MlirOpPassManager nestedModulePm = mlirPassManagerGetNestedUnder(
pm, mlirStringRefCreateFromCString("builtin.module"));
@@ -150,7 +151,7 @@ void testPrintPassPipeline() {
mlirOpPassManagerAddOwnedPass(nestedFuncPm, printOpStatPass);
// Print the top level pass manager
- // CHECK: Top-level: builtin.module(
+ // CHECK: Top-level: any(
// CHECK-SAME: builtin.module(func.func(print-op-stats{json=false}))
// CHECK-SAME: )
fprintf(stderr, "Top-level: ");
More information about the Mlir-commits
mailing list