[LLVMdev] Re: MRegisterInfo::storeRegToStackSlot question

Chris Lattner sabre at nondot.org
Mon May 15 12:40:08 PDT 2006


On Mon, 15 May 2006, Vladimir Prus wrote:
> Chris Lattner wrote:
>> On Sat, 13 May 2006, Vladimir Prus wrote:
>>> in LLVM CVS the afore-mentioned function has 'const TargetRegisterClass*'
>>> parameter, that is not documented.
>>> Can somebody explain what does it mean?
>>
>> Basically, it gives the target more information about the spill.  In
>> particular, it specifies the register class to use for the copy.
>
> I'm still missing something. The 'storeRegToStackSlot' saves
> 'SrcReg' (already specified) to stack (which is not a register). So, what
> does this register class applies to?

It applies to the register class.  Memory (the stack slot) doesn't have a 
register class.

> Examining RegAllocLocal.cpp suggests that the argument actually specifies
> the register class of the spilled virtual register.

Right.

> Can you give some examples how that information can be helpful?

Take a look at how some other targets use implement this.  PPC, for 
example, uses this:

   if (RC == PPC::GPRCRegisterClass) {
     addFrameReference(BuildMI(MBB, MI, PPC::STW, 3).addReg(SrcReg),FrameIdx);
   } else if (RC == PPC::G8RCRegisterClass) {
     addFrameReference(BuildMI(MBB, MI, PPC::STD, 3).addReg(SrcReg),FrameIdx);
   } else if (RC == PPC::F8RCRegisterClass) {
     addFrameReference(BuildMI(MBB, MI, PPC::STFD, 3).addReg(SrcReg),FrameIdx);
   } else if (RC == PPC::F4RCRegisterClass) {
     addFrameReference(BuildMI(MBB, MI, PPC::STFS, 3).addReg(SrcReg),FrameIdx);
   } else if (RC == PPC::VRRCRegisterClass) {
...

If you didn't have the register class (in the "bad old days") the target 
had to do two things:

1. For virtual registers, it had to look up the regclass in the SSARegMap.
    This is an extra step, but was efficient and not too problematic.
2. For physregs, you either had to switch on every physreg (ugly!) or scan
    through all the register classes to find out which regclass a physreg
    was in (slow!).  Additionally, physregs can be in multiple register
    classes, which could potentially be a problem.

Again, as mentioned before, this is just extra information provided to the 
target.  The target can figure out, however it wants, how to handle the 
register.  The regclass is just a convenient way to do this. :)

> I'd like to send doc patch, but can't do that without understanding the
> semantics ;-)

Thanks!!

-Chris

-- 
http://nondot.org/sabre/
http://llvm.org/




More information about the llvm-dev mailing list