Skip to content

Visualizing MLIR codes to generate DFGs through graphviz#110

Merged
tancheng merged 11 commits intocoredac:mainfrom
HobbitQia:main
Sep 4, 2025
Merged

Visualizing MLIR codes to generate DFGs through graphviz#110
tancheng merged 11 commits intocoredac:mainfrom
HobbitQia:main

Conversation

@HobbitQia
Copy link
Copy Markdown
Collaborator

The document and example can be found in test/visualize.

@HobbitQia
Copy link
Copy Markdown
Collaborator Author

It seems that this PR should be resolved first then I can keep pushing new commits to my GitHub repo...

@tancheng
Copy link
Copy Markdown
Contributor

It seems that this PR should be resolved first then I can keep pushing new commits to my GitHub repo...

It would be perfect if a PR is this small :-)
But why this PR should be merged first, you are always able to push stuff into your branch, right? What am I missing?

@tancheng tancheng added the new feature New feature or request label Aug 16, 2025
@HobbitQia
Copy link
Copy Markdown
Collaborator Author

It seems that this PR should be resolved first then I can keep pushing new commits to my GitHub repo...

It would be perfect if a PR is this small :-) But why this PR should be merged first, you are always able to push stuff into your branch, right? What am I missing?

Yes. currently this PR only contains the basic steps to visualize DFGs without something about assemblyFormat. I mean if I push my further commits to my repos, these commits will automatically become a part of this PR, which is not what we want to see so I revert them in e7c1903.

@HobbitQia
Copy link
Copy Markdown
Collaborator Author

Thanks for Shangkun's help! Now we can solely rely onmlir-neura-opt to generate dot files and I have modified test.mlir so it can pass tests locally.

@HobbitQia
Copy link
Copy Markdown
Collaborator Author

HobbitQia commented Aug 28, 2025

Hi @tancheng

When I try to enable multiple createPrintOpGraph passes in neuraPasses.cpp, I found that there will be much output information in stderr (not only dot file). e.g., [ctrl2data] Asserting live-out values dominated by block arguments. It will influence the generation of the png since graphviz cannot neglect this information to proceed its generation.

@ShangkunLi
Copy link
Copy Markdown
Collaborator

Hi @tancheng

When I try to enable multiple createPrintOpGraph passes in neuraPasses.cpp, I found that there will be much output information in stderr (not only dot file). e.g., [ctrl2data] Asserting live-out values dominated by block arguments. It will influence the generation of the png since graphviz cannot neglect this information to proceed its generation.

The problem comes from trying to convert stderr into content in a file by using 2>&1. This will convert all the debugging info printed by llvm::errs() into a file.

I think a better way would be to explicitly assign an os for the --view-op-graph pass when we create this pass. Or it will use the llvm::errs() as the os by default.
https://github.com/llvm/llvm-project/blob/78b45b489559cd44437af4eac6c10188eb0cec3c/mlir/lib/Transforms/ViewOpGraph.cpp#L102

For example,

std::string filename = "opgraph.dot";
llvm::raw_fd_ostream os(filename, ec);
pm.addPass(mlir::createPrintOpGraphPass(os));

@tancheng tancheng merged commit fe3bc16 into coredac:main Sep 4, 2025
1 check passed
@tancheng tancheng linked an issue Sep 4, 2025 that may be closed by this pull request
ShangkunLi pushed a commit that referenced this pull request Mar 12, 2026
Visualizing MLIR codes to generate DFGs through graphviz
ShangkunLi pushed a commit that referenced this pull request Mar 12, 2026
Visualizing MLIR codes to generate DFGs through graphviz
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

new feature New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[P1] Readable DFG generation

4 participants