9#ifndef MLIR_BINDINGS_PYTHON_REWRITE_H
10#define MLIR_BINDINGS_PYTHON_REWRITE_H
15#include <nanobind/nanobind.h>
22template <
typename DerivedTy>
33 if (mlirOperationIsNull(op)) {
42 static void bind(nanobind::module_ &m) {
43 nanobind::class_<DerivedTy>(m, DerivedTy::pyClassName)
45 "The current insertion point of the PatternRewriter.")
52 "Replace an operation with a new operation.", nanobind::arg(
"op"),
53 nanobind::arg(
"new_op"))
57 const std::vector<PyValue> &values) {
58 std::vector<MlirValue> values_(values.size());
59 std::copy(values.begin(), values.end(), values_.begin());
61 self.base, op.
getOperation(), values_.size(), values_.data());
63 "Replace an operation with a list of values.", nanobind::arg(
"op"),
64 nanobind::arg(
"values"))
70 "Erase an operation.", nanobind::arg(
"op"));
Wrapper around an MlirBlock.
An insertion point maintains a pointer to a Block and a reference operation.
Base class for PyOperation and PyOpView which exposes the primary, user visible methods for manipulat...
virtual PyOperation & getOperation()=0
Each must provide access to the raw Operation.
static PyOperationRef forOperation(PyMlirContextRef contextRef, MlirOperation operation, nanobind::object parentKeepAlive=nanobind::object())
Returns a PyOperation for the given MlirOperation, optionally associating it with a parentKeepAlive.
static void bind(nanobind::module_ &m)
PyRewriterBase(MlirRewriterBase rewriter)
PyInsertionPoint getInsertionPoint() const
MLIR_CAPI_EXPORTED void mlirRewriterBaseReplaceOpWithValues(MlirRewriterBase rewriter, MlirOperation op, intptr_t nValues, MlirValue const *values)
Replace the results of the given (original) operation with the specified list of values (replacements...
MLIR_CAPI_EXPORTED MlirOperation mlirRewriterBaseGetOperationAfterInsertion(MlirRewriterBase rewriter)
Returns the operation right after the current insertion point of the rewriter.
MLIR_CAPI_EXPORTED void mlirRewriterBaseEraseOp(MlirRewriterBase rewriter, MlirOperation op)
Erases an operation that is known to have no uses.
MLIR_CAPI_EXPORTED MlirContext mlirRewriterBaseGetContext(MlirRewriterBase rewriter)
RewriterBase API inherited from OpBuilder.
MLIR_CAPI_EXPORTED void mlirRewriterBaseReplaceOpWithOperation(MlirRewriterBase rewriter, MlirOperation op, MlirOperation newOp)
Replace the results of the given (original) operation with the specified new op (replacement).
MLIR_CAPI_EXPORTED MlirBlock mlirRewriterBaseGetInsertionBlock(MlirRewriterBase rewriter)
Return the block the current insertion point belongs to.
MLIR_CAPI_EXPORTED MlirOperation mlirBlockGetParentOperation(MlirBlock)
Returns the closest surrounding operation that contains this block.
#define MLIR_PYTHON_API_EXPORTED
void populateRewriteSubmodule(nb::module_ &m)
Create the mlir.rewrite here.
PyObjectRef< PyMlirContext > PyMlirContextRef
Wrapper around MlirContext.
Include the generated interface declarations.