/** Gets the context that a module was created with. */
MlirContext mlirModuleGetContext(MlirModule module);
+/** Gets the body of the module, i.e. the only block it contains. */
+MlirBlock mlirModuleGetBody(MlirModule module);
+
/** Checks whether a module is null. */
static inline int mlirModuleIsNull(MlirModule module) { return !module.ptr; }
.releaseObject();
},
"Accesses the module as an operation")
+ .def_property_readonly(
+ "body",
+ [](PyModule &self) {
+ PyOperationRef module_op = PyOperation::forOperation(
+ self.getContext(), mlirModuleGetOperation(self.get()),
+ self.getRef().releaseObject());
+ PyBlock returnBlock(module_op, mlirModuleGetBody(self.get()));
+ return returnBlock;
+ },
+ "Return the block for this module")
.def(
"dump",
[](PyModule &self) {
return wrap(unwrap(module).getContext());
}
+MlirBlock mlirModuleGetBody(MlirModule module) {
+ return wrap(unwrap(module).getBody());
+}
+
void mlirModuleDestroy(MlirModule module) {
// Transfer ownership to an OwningModuleRef so that its destructor is called.
OwningModuleRef(unwrap(module));
f32 = mlir.ir.F32Type.get(ctx)
loc = ctx.get_unknown_location()
m = ctx.create_module(loc)
- m_block = m.operation.regions[0].blocks[0]
+ m_block = m.body
# TODO: Remove integer insertion in favor of InsertionPoint and/or op-based.
ip = [0]
def createInput():
MlirModule makeAdd(MlirContext ctx, MlirLocation location) {
MlirModule moduleOp = mlirModuleCreateEmpty(location);
- MlirOperation module = mlirModuleGetOperation(moduleOp);
- MlirRegion moduleBodyRegion = mlirOperationGetRegion(module, 0);
- MlirBlock moduleBody = mlirRegionGetFirstBlock(moduleBodyRegion);
+ MlirBlock moduleBody = mlirModuleGetBody(moduleOp);
MlirType memrefType = mlirTypeParseGet(ctx, "memref<?xf32>");
MlirType funcBodyArgTypes[] = {memrefType, memrefType};