[LLVMdev] LLVM ERROR: ran out of registers during register allocation
Jakob Stoklund Olesen
stoklund at 2pi.dk
Mon Dec 17 10:12:50 PST 2012
On Dec 17, 2012, at 8:38 AM, Borja Ferrer <borja.ferav at gmail.com> wrote:
> I'm getting the "LLVM ERROR: ran out of registers during register allocation" error message for an out of tree target I'm developing. This is happening for the following piece of C code:
> struct ss
> int a;
> int b;
> int c;
> void loop(struct ss *x, struct ss **y, int z)
> int i;
> for (i=0; i<z; ++i)
> x->c += y[i]->b;
> The problem relies in the register classes for the load and store with displacement instructions:
> - load DREGS:$dst, PTR:$p
> - store DREGS:$src, PTR:$p
> where DREGS is a regclass composed of 16 registers and PTR is a regclass composed of 2 registers, but the key point here is that PTR is a subset of DREGS, so cross class copies are perfectly allowed.
> One of the 2 registers in the PTR regclass is reserved for the frame pointer, leaving only one register to access both x and y[i] in the code above, which seems to confuse the regalloc. Implementing getLargestLegalSuperClass() sort of helped for simpler functions, but not for this one.
> This code can be register-allocted if the addresses of both x and y[i] are cross class copied to DREGS registers to temporarily store these values and then when required copied back to the the register in PTR to access them in memory.
> Any help for a solution or a workaround will be greatly appreciated since this problem is severily limiting the complexity of the programs that I can currently compile.
Those are some severe constraints on register allocation, but it ought to be possible anyway.
You may wan't to investigate how RAGreedy::canEvictInterference() is behaving.
More information about the llvm-dev