Skip to content

Rewrite MIR#170

Draft
dcbaker wants to merge 120 commits into
mainfrom
submit/rewrite-mir
Draft

Rewrite MIR#170
dcbaker wants to merge 120 commits into
mainfrom
submit/rewrite-mir

Conversation

@dcbaker

@dcbaker dcbaker commented Jun 2, 2026

Copy link
Copy Markdown
Owner

There's a whole bunch of issues with the current MIR implementation, this is an attempt to rewrite MIR to fix that.

Currently this is enough that most projects can be converted to MIR, and most concepts can be represented. There are still a number of missing things:

  • phi insertions
  • use-def chains
  • def-use chains
  • copy-on-assign vs reference-on-assign functions
  • convert to FIR serialize Ninja

dcbaker added 30 commits October 8, 2025 11:25
Let's just try again, with a new attempt to write an SSA based
intermediate IR, with some of the knowledge gleaned from the previous
attempt.
This will give us a way to represent the state of the IR at each pass in
a way that is both relatively human readable, and also in a format that
a machine could (in theory) de-serialize
Message is a distinct enough type of thing in Meson it gets it's own
implementation. It's might be a pure side effect (print this message),
it might also cause the program to abort.
I'm not sure how I feel about this, I kinda want to keep the
`InstructionType` variant small and simple.
dcbaker added 30 commits April 16, 2026 14:57
I'm going to represent this as a function instead
The idea here is that as we can identify the namespace of the function,
we can set this enum and then use it to quickly look up what the
function is by using case statements instead of having to do complex
string matching. The names remain because they are nice for human
readability
These can be written as `not x == y` and `not x in y`, which saves us
some opcodes in our FunctionId
We need the shared pointers sometimes, and the only way to get that is
from the CFG itself. This also removes the Node iterator, which was
broken when not called from the root node anyway
This is the first step to allowing us to iterate from any point on the
graph.
This will allow us to write a faster and more flexible iterator
Using our depth we can iterate from any point on the graph, since we
have the depth to know when we have reached a peer or predecessor level
node of our starting point. We should also now be able to implement a
reverse iterator very easily.
This time I have a different idea. If the owning structure is a vector,
then we can sort that vector. This means we can actually do a linear
walk iteration by sorting ahead of time, and this walk would work in
both the forward and backward direction, while not requiring as much
special handling, maybe not even needing the special end node. The trick
to this is that we then have to keep the vector in order, top to bottom,
left to right.
The BasicBlock was only holding a list of instructions, It just didn't
make sense to have it anymore.
BasicBlock is dead, long live BasicBlock!
Because this will make use-def and def-use chains much simpler
I'm going to drop the optparser and use this instead.
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

Successfully merging this pull request may close these issues.

1 participant