Print MLIR module

I am very new to MLIR world.
I built a mlir module with c++ builder API, like this
auto module = mlir::ModuleOp::create(mlir::UnknownLoc::get(&ctx) , StringRef(“mainModule”));

I added some other Ops(Func Op/ myDialect Ops) inside Module.
I want to see the assembly format for created Module at the end, how to I do that ?

Currently I am using a mlir pass mlir::createPrintOpGraphPass() to do that, but it prints lot of information I don’t really need.

Can someone guide on this ?

module.dump() prints the module to stderr, module.print(stream) prints the module to the given output stream, e.g., llvm::outs() for stdout. This also works for most other IR objects.

1 Like

Yes and it doesn’t so as pretty as it could :slight_smile: This pass creates a basic graph in graphviz format per block.

As Alex pointed out, print and dump are more appropriate and easier (one can even invoke from one’s debugger). “Pass” wise the easiest is to enable printing on the pass manager, then you would get a dump before and after every pass.

Fantastic ! Thank you. module.dump() works great for me.

Thanks for the suggestion on Passmanager ! That would be great to have, How do I enable IR printing though ?

Something like --print-ir-after-all. More details at Pass Infrastructure - MLIR

Welcome to the community!

Another method that I often use during development is:

myop.emitWarning() << "Custom Debug Message";

During runtime it will point to the operation and file location that gave origin to myop (useful when several passes were used) and print to the terminal the mlir code of myop.

Hi @sachinmuradi007 ,I am interested in your module building, can you share your example code?