eirproject / eir

Erlang ecosystem common IR
Apache License 2.0
250 stars 8 forks source link

Thorin refactor #15

Closed hansihe closed 5 years ago

hansihe commented 5 years ago

This contains the skeleton implementation of https://github.com/eirproject/eir/issues/11. Do not merge yet.

After iterating I landed on not having basic blocks at all, contrary to what I said in the issue.

The core of the IR is 'fun::Function'. It contains two primary entities, Blocks and Values.

Blocks are equivalent of an abstraaction. Blocks can take any number of arguments. They can contain an operation, or be empty. Empty blocks are for use by the builder API only, and are not allowed in a completed function. Operations are documented in 'op::OpKind'.

Blocks keep track of their predecessors as the IR is built/mutated. This is a necessity for cheap graph queries.

Values can be one of three types:

Arena allocation is used everywhere, and with the exception of a few temporary spots and the arenas themselves, building and mutating the IR will not do any allocations. 'cranelift_entity' is used for this. This gives us really cheap allocations and graph mutations, but the compromise is that unused slots will never be deallocated until the whole structure is deallocated. There will be a utility function for copying a Function instance and removing garbage, but I don't expect this to be used often.

Things that are missing:

I will keep working towards a more complete API for use by codegen, then go back to Hir for a bit, and finish the API here when implementing Hir lowering.

hansihe commented 5 years ago

No real reason to have this on a branch anymore, merged it