16#include <mlir/CAPI/IR.h>
17#include <mlir/CAPI/Support.h>
18#include <mlir/CAPI/Wrap.h>
19#include <mlir/IR/Builders.h>
29class ListenerT :
public OpBuilder::Listener {
32 : opInsertedCb(op), blockInsertedCb(block), userData(data) {}
36 void notifyOperationInserted(Operation *op, OpBuilder::InsertPoint previous)
final {
38 .block = wrap(previous.getBlock()), .point = wrap(&*previous.getPoint())
40 opInsertedCb(wrap(op), i, userData);
45 void notifyBlockInserted(Block *block, Region *previous, Region::iterator previousIt)
final {
46 blockInsertedCb(wrap(block), wrap(previous), wrap(&*previousIt), userData);
52 void *userData =
nullptr;
63 return MlirOpBuilder {.ptr =
new OpBuilderT(unwrap(ctx))};
69 auto *l =
reinterpret_cast<ListenerT *
>(listener.ptr);
70 return MlirOpBuilder {.ptr =
new OpBuilderT(unwrap(ctx), l)};
75 delete reinterpret_cast<OpBuilderT *
>(builder.ptr);
80 return wrap(unwrap(builder)->getContext());
86 unwrap(builder)->setInsertionPointToStart(unwrap(block));
92 auto it = unwrap(builder)->getInsertionPoint();
93 auto *blk = unwrap(builder)->getInsertionBlock();
95 return MlirOperation {
nullptr};
98 return wrap(it != blk->end() ? &*it :
nullptr);
104 return wrap(unwrap(builder)->getInsertionBlock());
109 return wrap(unwrap(builder)->insert(unwrap(op)));
122 return MlirOpBuilderListener {.ptr =
new ListenerT(opCb, blockCb, userData)};
127 delete reinterpret_cast<ListenerT *
>(listener.ptr);
void mlirOpBuilderDestroy(MlirOpBuilder builder)
Destroys builder and frees the underlying OpBuilder object.
MlirOpBuilder mlirOpBuilderCreate(MlirContext ctx)
Creates a new OpBuilder for the given MLIR context.
MlirOpBuilder mlirOpBuilderCreateWithListener(MlirContext ctx, MlirOpBuilderListener listener)
Creates a new OpBuilder for the given MLIR context and attaches listener so that operation and block ...
void mlirOpBuilderSetInsertionPointToStart(MlirOpBuilder builder, MlirBlock block)
Sets the insertion point of builder to the beginning of block so that subsequent insertions prepend t...
MlirOperation mlirOpBuilderGetInsertionPoint(MlirOpBuilder builder)
Returns the operation before which new operations will be inserted, or a null MlirOperation if there ...
void mlirOpBuilderListenerDestroy(MlirOpBuilderListener listener)
Destroys listener and frees the underlying ListenerT object.
MlirBlock mlirOpBuilderGetInsertionBlock(MlirOpBuilder builder)
Returns the block that builder is currently inserting into, or a null MlirBlock if no insertion point...
MlirOpBuilderListener mlirOpBuilderListenerCreate(MlirNotifyOperationInserted opCb, MlirNotifyBlockInserted blockCb, void *userData)
Creates a new OpBuilder::Listener that calls opCb whenever an operation is inserted and blockCb whene...
MlirContext mlirOpBuilderGetContext(MlirOpBuilder builder)
Returns the MLIR context associated with builder.
MlirOperation mlirOpBuilderInsert(MlirOpBuilder builder, MlirOperation op)
Inserts op at the current insertion point of builder and returns it.
void(* MlirNotifyOperationInserted)(MlirOperation, MlirOpBuilderInsertPoint, void *)
Callback type for listening to operation insertions in an mlir::OpBuilder.
void(* MlirNotifyBlockInserted)(MlirBlock, MlirRegion, MlirBlock, void *)
Callback type for listening to block insertions in an mlir::OpBuilder.
Current insertion point of an mlir::OpBuilder instance represented as a block and an operation within...