2020-11-05 02:08:34 +08:00
|
|
|
//===-- mlir-c/Pass.h - C API to Pass Management ------------------*- C -*-===//
|
|
|
|
//
|
|
|
|
// 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
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
//
|
|
|
|
// This header declares the C interface to MLIR pass manager.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
2020-11-04 05:38:34 +08:00
|
|
|
|
|
|
|
#ifndef MLIR_C_PASS_H
|
|
|
|
#define MLIR_C_PASS_H
|
|
|
|
|
|
|
|
#include "mlir-c/IR.h"
|
|
|
|
#include "mlir-c/Support.h"
|
|
|
|
|
|
|
|
#ifdef __cplusplus
|
|
|
|
extern "C" {
|
|
|
|
#endif
|
|
|
|
|
2020-11-05 02:08:34 +08:00
|
|
|
//===----------------------------------------------------------------------===//
|
2021-01-25 22:22:16 +08:00
|
|
|
// Opaque type declarations.
|
|
|
|
//
|
|
|
|
// Types are exposed to C bindings as structs containing opaque pointers. They
|
|
|
|
// are not supposed to be inspected from C. This allows the underlying
|
|
|
|
// representation to change without affecting the API users. The use of structs
|
|
|
|
// instead of typedefs enables some type safety as structs are not implicitly
|
|
|
|
// convertible to each other.
|
|
|
|
//
|
|
|
|
// Instances of these types may or may not own the underlying object. The
|
|
|
|
// ownership semantics is defined by how an instance of the type was obtained.
|
2020-11-05 02:08:34 +08:00
|
|
|
//===----------------------------------------------------------------------===//
|
2020-11-04 05:38:34 +08:00
|
|
|
|
|
|
|
#define DEFINE_C_API_STRUCT(name, storage) \
|
|
|
|
struct name { \
|
|
|
|
storage *ptr; \
|
|
|
|
}; \
|
|
|
|
typedef struct name name
|
|
|
|
|
|
|
|
DEFINE_C_API_STRUCT(MlirPass, void);
|
|
|
|
DEFINE_C_API_STRUCT(MlirPassManager, void);
|
|
|
|
DEFINE_C_API_STRUCT(MlirOpPassManager, void);
|
|
|
|
|
|
|
|
#undef DEFINE_C_API_STRUCT
|
|
|
|
|
2020-11-05 02:08:34 +08:00
|
|
|
/// Create a new top-level PassManager.
|
2020-11-09 08:49:36 +08:00
|
|
|
MLIR_CAPI_EXPORTED MlirPassManager mlirPassManagerCreate(MlirContext ctx);
|
2020-11-04 05:38:34 +08:00
|
|
|
|
2020-11-05 02:08:34 +08:00
|
|
|
/// Destroy the provided PassManager.
|
2020-11-09 08:49:36 +08:00
|
|
|
MLIR_CAPI_EXPORTED void mlirPassManagerDestroy(MlirPassManager passManager);
|
2020-11-04 05:38:34 +08:00
|
|
|
|
2020-11-11 12:59:18 +08:00
|
|
|
/// Checks if a PassManager is null.
|
2020-11-30 10:31:11 +08:00
|
|
|
static inline bool mlirPassManagerIsNull(MlirPassManager passManager) {
|
2020-11-11 12:59:18 +08:00
|
|
|
return !passManager.ptr;
|
|
|
|
}
|
|
|
|
|
2020-11-05 02:08:34 +08:00
|
|
|
/// Cast a top-level PassManager to a generic OpPassManager.
|
2020-11-09 08:49:36 +08:00
|
|
|
MLIR_CAPI_EXPORTED MlirOpPassManager
|
2020-11-04 08:08:35 +08:00
|
|
|
mlirPassManagerGetAsOpPassManager(MlirPassManager passManager);
|
|
|
|
|
2020-11-05 02:08:34 +08:00
|
|
|
/// Run the provided `passManager` on the given `module`.
|
2020-11-09 08:49:36 +08:00
|
|
|
MLIR_CAPI_EXPORTED MlirLogicalResult
|
|
|
|
mlirPassManagerRun(MlirPassManager passManager, MlirModule module);
|
2020-11-04 05:38:34 +08:00
|
|
|
|
2021-04-16 20:54:43 +08:00
|
|
|
/// Enable print-ir-after-all.
|
|
|
|
MLIR_CAPI_EXPORTED void
|
|
|
|
mlirPassManagerEnableIRPrinting(MlirPassManager passManager);
|
|
|
|
|
|
|
|
/// Enable / disable verify-each.
|
|
|
|
MLIR_CAPI_EXPORTED void
|
|
|
|
mlirPassManagerEnableVerifier(MlirPassManager passManager, bool enable);
|
|
|
|
|
2021-01-25 22:22:16 +08:00
|
|
|
/// Nest an OpPassManager under the top-level PassManager, the nested
|
|
|
|
/// passmanager will only run on operations matching the provided name.
|
|
|
|
/// The returned OpPassManager will be destroyed when the parent is destroyed.
|
|
|
|
/// To further nest more OpPassManager under the newly returned one, see
|
|
|
|
/// `mlirOpPassManagerNest` below.
|
2020-11-09 08:49:36 +08:00
|
|
|
MLIR_CAPI_EXPORTED MlirOpPassManager mlirPassManagerGetNestedUnder(
|
|
|
|
MlirPassManager passManager, MlirStringRef operationName);
|
2020-11-04 05:38:34 +08:00
|
|
|
|
2021-01-25 22:22:16 +08:00
|
|
|
/// Nest an OpPassManager under the provided OpPassManager, the nested
|
|
|
|
/// passmanager will only run on operations matching the provided name.
|
|
|
|
/// The returned OpPassManager will be destroyed when the parent is destroyed.
|
2020-11-09 08:49:36 +08:00
|
|
|
MLIR_CAPI_EXPORTED MlirOpPassManager mlirOpPassManagerGetNestedUnder(
|
|
|
|
MlirOpPassManager passManager, MlirStringRef operationName);
|
2020-11-04 05:38:34 +08:00
|
|
|
|
2021-01-25 22:22:16 +08:00
|
|
|
/// Add a pass and transfer ownership to the provided top-level mlirPassManager.
|
|
|
|
/// If the pass is not a generic operation pass or a ModulePass, a new
|
|
|
|
/// OpPassManager is implicitly nested under the provided PassManager.
|
2020-11-09 08:49:36 +08:00
|
|
|
MLIR_CAPI_EXPORTED void mlirPassManagerAddOwnedPass(MlirPassManager passManager,
|
|
|
|
MlirPass pass);
|
2020-11-04 05:38:34 +08:00
|
|
|
|
2021-01-25 22:22:16 +08:00
|
|
|
/// Add a pass and transfer ownership to the provided mlirOpPassManager. If the
|
|
|
|
/// pass is not a generic operation pass or matching the type of the provided
|
|
|
|
/// PassManager, a new OpPassManager is implicitly nested under the provided
|
|
|
|
/// PassManager.
|
2020-11-09 08:49:36 +08:00
|
|
|
MLIR_CAPI_EXPORTED void
|
|
|
|
mlirOpPassManagerAddOwnedPass(MlirOpPassManager passManager, MlirPass pass);
|
2020-11-04 05:38:34 +08:00
|
|
|
|
2021-01-25 22:22:16 +08:00
|
|
|
/// Print a textual MLIR pass pipeline by sending chunks of the string
|
|
|
|
/// representation and forwarding `userData to `callback`. Note that the
|
|
|
|
/// callback may be called several times with consecutive chunks of the string.
|
2020-11-09 08:49:36 +08:00
|
|
|
MLIR_CAPI_EXPORTED void mlirPrintPassPipeline(MlirOpPassManager passManager,
|
|
|
|
MlirStringCallback callback,
|
|
|
|
void *userData);
|
2020-11-04 08:08:35 +08:00
|
|
|
|
2021-01-25 22:22:16 +08:00
|
|
|
/// Parse a textual MLIR pass pipeline and add it to the provided OpPassManager.
|
|
|
|
|
2020-11-09 08:49:36 +08:00
|
|
|
MLIR_CAPI_EXPORTED MlirLogicalResult
|
|
|
|
mlirParsePassPipeline(MlirOpPassManager passManager, MlirStringRef pipeline);
|
2020-11-04 08:08:35 +08:00
|
|
|
|
2020-11-04 05:38:34 +08:00
|
|
|
#ifdef __cplusplus
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#endif // MLIR_C_PASS_H
|