[LLVMdev] Recalculating live intervals

Fernando Magno Quintao Pereira fernando at CS.UCLA.EDU
Wed Aug 23 12:26:58 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.
>

Hey, Daniel,

I am using the spiller from LLVM in order to insert spill code. My
register allocator decides which registers to spill, breaks its live range
by replacing each of its use by a new virtual register, and assign
physical registers to each of these virtuals. This information is passed
to the spiller via two methods of the VirtRegMap class: assignVirt2Phys,
that maps a  virtual to a particular physical, and assignVirt2StackSlot,
that maps a virtual to a stack position. After register allocation is
done, the spiller inserts the loads and stores. This insertion is always
possible, because all the virtual registers, even those generated after
spilling, are mapped to some physical register.

Fernando



More information about the llvm-dev mailing list