[LLVMdev] request for help writing a register allocator
Susan Horwitz
horwitz at cs.wisc.edu
Wed Oct 28 19:46:48 PDT 2009
I'm having no luck getting my register allocator to work. I'm trying to
do it using the "indirect" approach; i.e., using a VirtRegMap, with calls
to assignVirt2Phys, assignVirt2StackSlot, etc. and a call to a "spiller"
at the end.
As a warm-up exercise (before implementing register allocation via graph
coloring) I'm trying to implement a very simple scheme in which NO
pseudo-registers are allocated to physical registers across instructions.
So for each virtual register I call assignVirt2StackSlot. I thought that
I should call assignVirt2Phys as well for each virtual register in an
instruction, mapping that vreg to an unused preg. For example, for an
instruction like this:
%reg1024<def> = MOV32rr %ESP
I assign virtual register 1024 to some available physical register in the
appropriate class so that the generated code will assign to that physical
register. (I also assign virtual register 1024 to a stack slot so that
the value assigned to the physical register is spilled to that slot.)
If a virtual register is used in an instruction, rather than defined, I
again assign it to a physical register preg (but not to a stack slot
because it will already have been assigned a slot) so that the generated
code will load from the stack into that preg.
However, if the same virtual register is used in two different
instructions, I get an abort with an error message saying that I'm trying
to assign a physical register to a virtual register that's already been
mapped. If I don't call assignVirt2Phys then I get an abort with an error
message saying that some virtual register was not assigned a physical
register.
I've tried calling addSpillPoint and addRestorePoint for every instruction
that involves a virtual register, and also not calling those functions,
and I still get the same aborts.
I would very much appreciate any help!
Susan Horwitz
More information about the llvm-dev
mailing list