Files
llvm/mlir/lib/CAPI/IR/Pass.cpp
Mehdi Amini f61d1028fa Add a basic C API for the MLIR PassManager as well as a basic TableGen backend for creating passes
This is exposing the basic functionalities (create, nest, addPass, run) of
the PassManager through the C API in the new header: `include/mlir-c/Pass.h`.

In order to exercise it in the unit-test, a basic TableGen backend is
also provided to generate a simple C wrapper around the pass
constructor. It is used to expose the libTransforms passes to the C API.

Reviewed By: stellaraccident, ftynse

Differential Revision: https://reviews.llvm.org/D90667
2020-11-04 06:36:31 +00:00

54 lines
1.9 KiB
C++

//===- Pass.cpp - C Interface for General Pass Management APIs ------------===//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
//
//===----------------------------------------------------------------------===//
#include "mlir-c/Pass.h"
#include "mlir/CAPI/IR.h"
#include "mlir/CAPI/Pass.h"
#include "mlir/CAPI/Support.h"
#include "mlir/CAPI/Utils.h"
#include "mlir/Pass/PassManager.h"
using namespace mlir;
/* ========================================================================== */
/* PassManager/OpPassManager APIs. */
/* ========================================================================== */
MlirPassManager mlirPassManagerCreate(MlirContext ctx) {
return wrap(new PassManager(unwrap(ctx)));
}
void mlirPassManagerDestroy(MlirPassManager passManager) {
delete unwrap(passManager);
}
MlirLogicalResult mlirPassManagerRun(MlirPassManager passManager,
MlirModule module) {
return wrap(unwrap(passManager)->run(unwrap(module)));
}
MlirOpPassManager mlirPassManagerGetNestedUnder(MlirPassManager passManager,
MlirStringRef operationName) {
return wrap(&unwrap(passManager)->nest(unwrap(operationName)));
}
MlirOpPassManager mlirOpPassManagerGetNestedUnder(MlirOpPassManager passManager,
MlirStringRef operationName) {
return wrap(&unwrap(passManager)->nest(unwrap(operationName)));
}
void mlirPassManagerAddOwnedPass(MlirPassManager passManager, MlirPass pass) {
unwrap(passManager)->addPass(std::unique_ptr<Pass>(unwrap(pass)));
}
void mlirOpPassManagerAddOwnedPass(MlirOpPassManager passManager,
MlirPass pass) {
unwrap(passManager)->addPass(std::unique_ptr<Pass>(unwrap(pass)));
}