Register Allocation problem

Ok, i'm having a problem with understanding the allocating of registers. I've written in the "addPassesToEmitAssembly()" the passes to create the assembly code, as in the PowerPC example. I'ved tried filling up as much of the code in <Target>RegisterInfo.cpp (Register/Frame code) to handle writing and reading from stack.

The allocation method I used was -regalloc=simple, so it only wrote to 2 or 3 registers total, with a lot of loading and writing to stack.

If I use any of the regalloc parameters (local, ...) I get an error in the LiveVariable.cpp file, in the part that I think cheaks for dead code because a Variable didn't have a defined Instance to a Machine instruction.

llc: LiveVariables.cpp:86: void llvm::LiveVariables::HandleVirtRegUse(llvm::LiveVariables::VarInfo&, llvm::MachineBasicBlock*, llvm::MachineInstr*): Assertion `VRInfo.DefInst && "Register use before def!"' failed.
/home/llvm/Debug/bin/llc((anonymous namespace)::PrintStackTrace()+0x1a)[0x86abeda]
/home/llvm/Debug/bin/llc((anonymous namespace)::SignalHandler(int)+0xcb)[0x86ac14d]

Is there any passes that need to occur to correct this error? For the passes in emitting assembly I have this:

" PM.add(createLowerGCPass());







   PM.add(create<MYTARGET>AsmPrinter(Out, *this));

The backend target I'm writing is to a subset of MIPS32, so I borrowed some amount of code from PowerPC.

Thanks for any help.

This is a bug in your instruction selector and the assertion is telling
you exactly what's wrong. Registers in MachineInstrs are also in SSA --
there must be a single static def of any register before its use.

To help you narrow down the bug to a small test case, you can use

That should catch crashes in llc and give you a tiny test case to work
with. If that doesn't help, let us know.

Another note: if you can't figure out what the problem is, please send the output of llc with the -print-machineinstrs flag to the list, and we'll try to help :slight_smile: