Dumping the use-def chain of newly created/added Operators in matchAndRewrite()

Is there a utility function to dump a set of newly created Operators through rewriter.createOrFold while doing a Dialect Conversion in matchAndRewrite()

I can dump the individual operations and their operand/result using a utility function

But I want to dump the entire IR of newly created instructions starting from the firstly created instruction to ensure that the use-def generated chain is as per expectation for the new set of instructions getting created in matchAndRewrite() .

With old operation which came as argument to matchAndRewrite() it prints all the instructions in the Block .
llvm::dbgs() << "New Op " << “\n”;
auto walkFnNewOp = [&](Operation *walkedOp) {
for (Region &region : definingOp->getRegions())

But on the newly created Value object but it didn’t dump anything, probably there is no region with newly created Value.

I would say inspecting the IR while in dialect conversion isn’t a great idea unless you have a good understanding of how the conversion infra works. I would rather suggest dumping it immediately after the applyFull/PartialConversion call.

In short, the conversion infra keeps most, but not all, original IR along with the newly created IR during the transformation process for type resolution and rollback functionality. One cannot tell just by looking at the IR which operations will persist after the conversion terminates. As a particular example relevant to your use case, rewriter.replaceOpWithNewOp(oldOp,...) does not immediately remove oldOp, neiter does it immediately update the users of oldOp results with results of the new operation. Instead, the mapping between old and new values is stored inside the conversion infra and the actual replacement will happen at the end of the process, going through materialization hooks if the types of values differ. So the new operation is unlikely to have any users when created.

Thanks, Alex

Dumping it immediately after the applyFull/PartialConversion call - Yes I am trying to do that now.

In addition, I have enabled the “dialect-conversion” debug messages in function legalize/finalize/applyWrites etc and lib/Transforms/Utils/DialectConversion.cpp and have introduced some additional debug messages, and it is giving some insight.

BTW Do we have some doc or writeup particular on the internals of Dialect Conversion Framework
specifically for these ones.

legalize/finalize/applyWrites/convertOperations/TypeConversion/replaceOp/materializeConversion/splitBlock/mergingBlocks/walk operation/use-def chains/ creating erasing ops.


These belong to vastly different parts of the code base. Walking or use-def chains are absolutely not specific to conversion, neither are block manipulations. Look at the documentation, e.g. MLIR: mlir::RewriterBase Class Reference, and the implementation of the relevant classes.