The cost to spill is a combination of the reference number plus an extra bit for those values that flow to phi nodes. Due to the organization of the IR, constants will have a smaller cost than values defined outside the loop, which will have a smaller cost than values defined inside the loop. The extra phi-factor tries to ensure that values in phi nodes will get a register.
Previously we were running the codegen right before executing the trace. This was causing the extra IR instructions not to be emitted to the correct buffer (they were going to J->cur != F). We should be running the codegen at this point anyway.
The previous version was also subtracting SPS_FIRST so that we could use all the spill slots. The problem is that the spill area is zero indexed (i.e. spills is the first spill), but SPS_FIRST cannot be zero because a zero means no spill slot is allocated. As a result we simply don't use the first spill slot. This makes it easy to index into spills[ir->s] without having to worry about re-adjusting the index.
The base pointer points to base[-1] during exection of a trace. The fref appears to be indexed off of base, so we need to scale it properly in the codegen.
We now correctly generate the backwards branch for a loop. Correct codgen for resolving phi node mismatches. Correct codgen for fixing phi nodes spilled outside loop Phi nodes that are spilled only outside a loop need to have IR_RENAMEs emitted for them. We need to do this because if the LHS was spilled outside of the loop the snapshot restoration will attempt to load it from the spill slot. This spill slot will be out of date as the value changes in the loop. We emit a rename to ensure that snapshots will restore the value from the register inside the loop.
Using a position independent executable was causing the address for stg_IND_info to jump around because the OS X 10.7 randomizes the starting address of the executable. These varations were causing needless mental overhead to my debugging efforts in the code generator.