[LLVMdev] Recalculating live intervals

Daniel Berlin dberlin at dberlin.org
Wed Aug 23 11:48:09 PDT 2006


Fernando Magno Quintao Pereira wrote:
>> I'm not sure about one thing: you assign stack slot to each new register you
>> replace the spilled one with. And then you need to allocate physical
>> registers to them. Is it possible to assign physical register to the virtual
>> one which has a stack slot already?
>>
> 
> Yes. The stack slot is the place where the value will be stored in memory,
> but, when that value is effectively used in the code, you must load it
> into a physical register. Assume that reg_v is mapped to stack slot x, and
> there is an instruction such as add reg_1 := reg_v reg_2, where reg_1 is
> mapped to phys_1, reg_v is mapped to phys_v, and reg_2 is mapped to
> phys_2. Your final code will be like:
> 
> load phys_v, x
> add phys_1 := phys_v, phys_2
> 
> In order to insert load/store instructions, you can use the VirtRegMap
> class. The spiller, that is implemented in VirtRegMap.cpp will do that.
> For an example, see RegAllocLinearscan.cpp. Another way is to insert
> the load/store instructions yourself. This is done in RegAllocLocal.cpp,
> for example.

By the by, I don't remember whether you are inserting spills yourself or
not, but you really should try to not do that if you are.

It's much better to have an interface that knows how to spill things in
a good way, and how to place code for spills, and just use that, instead
of tying all the knowledge about how to spill directly into the allocator.

--Dan



More information about the llvm-dev mailing list