A typical compiler task is the register allocation issue. A given CPU has a limited number of registers to execute all the temporaries needed to calculate a given expression. Graph coloring is used to determine how the registers can be optimally utilized.
Since we’re coding a virtual machine, our problem is different. Basic steps:igure out is find the minimal number of registers needed to execute a piece of code.
- Figure out the minimal number of registers needed to execute a piece of code.
- Map all temporaries to a given register.
- Find the minimum size for each temporary.
Once this is implemented, it opens up some other interesting possibilities. We’ll be able to tell what the ram usage is. If we need for the virtual machine to have a smaller RAM footprint, we can open up the possiblity of allocating/deallocating more temporary registers as needed for RAM critical parts of the program. This would extend the working size of shader code, providing a tunable memory/performance control.
The solution is a graph coloring problem. Each Funct node is a graph node. Make a connection between nodes that depend on one another. If a set of nodes are arguments for a given node, (like a function with multiple arguments), all Funct arguments are interconnected. Then color the graph. The number of temporaries needed is the number of colors. Each node color points to the temporary used.So Boost has a
Graph Library. I’ll have to see if I can use it easily enough….Christ…. My current Boost implementation is Boost 1.31. So I had to upgrade to the latest Boost 1.34. The MSVC 7.1 compiler just chokes up and spits all over the place with its ‘Internal Compiler Error’. Half the libraries wont compile. Sucks. The online docs say that boost 1.34.1 should fix a lot of the compiler issues.Compiling with boost 1.34.1 allows compilation, but creates executables that wont run. The runtime library wont enter the ‘main’ method. The graph library will have to wait.