TritonVM / tasm-lang

Writing tasm with Rust syntax
15 stars 2 forks source link

Spill values to memory when stack becomes too deep #25

Closed Sword-Smith closed 1 year ago

Sword-Smith commented 1 year ago

The branch thv/dabble-with-value-spilling contains code for spilling values to memory if they cannot be accessed with a dup15/swap15.

For now, let's just spill to memory and print a warning if we do, and always access the value from memory/update it in memory. Then we can later add a liveness analysis to refine which values to spill and which we don't have to.

Sword-Smith commented 1 year ago

Note that if a value was spilled, we always have to use the memory-version of that value. As we would otherwise have to update both the memory version and the stack-version, and the stack version is inaccessible. Hence the spilling.

Sword-Smith commented 1 year ago

A problem is that different branches may spill variables differently. So a solution could be to run the compiler two times and see which values are inaccessible and which of those are actually needed when they are inaccessible. The values identified by those ValueIdentifiers are the ones that need to be spilled.

Sword-Smith commented 1 year ago

closed by b6627f09b2b257456a6693f7ab6ea05d38ec7de8