Skip to content

Commit f9f708e

Browse files
committed
[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
1 parent 2556ba4 commit f9f708e

File tree

3 files changed

+13
-3
lines changed

3 files changed

+13
-3
lines changed

mlir/include/mlir-c/Pass.h

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,9 +51,13 @@ DEFINE_C_API_STRUCT(MlirOpPassManager, void);
5151
// PassManager/OpPassManager APIs.
5252
//===----------------------------------------------------------------------===//
5353

54-
/// Create a new top-level PassManager.
54+
/// Create a new top-level PassManager with the default anchor.
5555
MLIR_CAPI_EXPORTED MlirPassManager mlirPassManagerCreate(MlirContext ctx);
5656

57+
/// Create a new top-level PassManager anchored on `anchorOp`.
58+
MLIR_CAPI_EXPORTED MlirPassManager
59+
mlirPassManagerCreateOnOperation(MlirContext ctx, MlirStringRef anchorOp);
60+
5761
/// Destroy the provided PassManager.
5862
MLIR_CAPI_EXPORTED void mlirPassManagerDestroy(MlirPassManager passManager);
5963

mlir/lib/CAPI/IR/Pass.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,11 @@ MlirPassManager mlirPassManagerCreate(MlirContext ctx) {
2424
return wrap(new PassManager(unwrap(ctx)));
2525
}
2626

27+
MlirPassManager mlirPassManagerCreateOnOperation(MlirContext ctx,
28+
MlirStringRef anchorOp) {
29+
return wrap(new PassManager(unwrap(ctx), unwrap(anchorOp)));
30+
}
31+
2732
void mlirPassManagerDestroy(MlirPassManager passManager) {
2833
delete unwrap(passManager);
2934
}

mlir/test/CAPI/pass.c

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,8 @@ static void dontPrint(MlirStringRef str, void *userData) {
140140

141141
void testPrintPassPipeline() {
142142
MlirContext ctx = mlirContextCreate();
143-
MlirPassManager pm = mlirPassManagerCreate(ctx);
143+
MlirPassManager pm = mlirPassManagerCreateOnOperation(
144+
ctx, mlirStringRefCreateFromCString("any"));
144145
// Populate the pass-manager
145146
MlirOpPassManager nestedModulePm = mlirPassManagerGetNestedUnder(
146147
pm, mlirStringRefCreateFromCString("builtin.module"));
@@ -150,7 +151,7 @@ void testPrintPassPipeline() {
150151
mlirOpPassManagerAddOwnedPass(nestedFuncPm, printOpStatPass);
151152

152153
// Print the top level pass manager
153-
// CHECK: Top-level: builtin.module(
154+
// CHECK: Top-level: any(
154155
// CHECK-SAME: builtin.module(func.func(print-op-stats{json=false}))
155156
// CHECK-SAME: )
156157
fprintf(stderr, "Top-level: ");

0 commit comments

Comments
 (0)