From f9f708ef41233bdc330cd8c6f82f48a1f5c962b0 Mon Sep 17 00:00:00 2001 From: rkayaith Date: Thu, 20 Oct 2022 00:51:06 -0400 Subject: [PATCH] [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 --- mlir/include/mlir-c/Pass.h | 6 +++++- mlir/lib/CAPI/IR/Pass.cpp | 5 +++++ mlir/test/CAPI/pass.c | 5 +++-- 3 files changed, 13 insertions(+), 3 deletions(-) diff --git a/mlir/include/mlir-c/Pass.h b/mlir/include/mlir-c/Pass.h index 6f281b6..704121a0 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 398abfe..30f5804 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 966bcaf..5b04d74 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: "); -- 2.7.4