Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Inline hugr functions #12

Closed
doug-q opened this issue Jan 21, 2025 · 0 comments
Closed

Inline hugr functions #12

doug-q opened this issue Jan 21, 2025 · 0 comments
Assignees

Comments

@doug-q
Copy link
Collaborator

doug-q commented Jan 21, 2025

we need to inline all functions to product valid qir.

We can do this in llvm, but I suggest we should do it in hugr, using:

We should create an Inline pass. I suggest that:

  • It should go into hugr-passes.
  • It should take as input a Vec<Node> and an &mut impl HugrMut. These nodes must be Call nodes.
  • The pass should construct a call graph from the hugr and ensure that the edges corresponding to the input calls do not form a cycle in the call graph. If they do, then return a "Can't inline a recursive cycle" error.
  • The pass should reverse-"toposort" the input call nodes in the call graph (https://docs.rs/petgraph/latest/petgraph/algo/fn.toposort.html).
  • It should then iterate the sorted list and apply InlineRewrite to the call nodes. This reverse-toposort ensures that we always inline a call before the function-thats-the-parent-of-the-call is inlined. Otherwise there would be copies of the input calls(with different Node ids) that would not be inlined

We should then create an InlineEverything pass here that collects all the call nodes in the Hugr and applies the Inline pass.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants