[llvm-commits] [llvm] r107847 - in /llvm/trunk: include/llvm/CodeGen/RegisterScavenging.h lib/CodeGen/PrologEpilogInserter.cpp lib/CodeGen/RegisterScavenging.cpp

Evan Cheng evan.cheng at apple.com
Wed Jul 7 21:59:59 PDT 2010



On Jul 7, 2010, at 7:48 PM, Jim Grosbach <grosbach at apple.com> wrote:

> 
> On Jul 7, 2010, at 6:23 PM, Jakob Stoklund Olesen wrote:
> 
>> 
>> On Jul 7, 2010, at 5:38 PM, Jim Grosbach wrote:
>>> Modified: llvm/trunk/lib/CodeGen/PrologEpilogInserter.cpp
>>> URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/CodeGen/PrologEpilogInserter.cpp?rev=107847&r1=107846&r2=107847&view=diff
>>> ==============================================================================
>>> --- llvm/trunk/lib/CodeGen/PrologEpilogInserter.cpp (original)
>>> +++ llvm/trunk/lib/CodeGen/PrologEpilogInserter.cpp Wed Jul  7 19:38:54 2010
>>> @@ -885,10 +885,20 @@
>>>           // Scavenge a new scratch register
>>>           CurrentVirtReg = Reg;
>>>           const TargetRegisterClass *RC = Fn.getRegInfo().getRegClass(Reg);
>>> -            CurrentScratchReg = RS->FindUnusedReg(RC);
>>> -            if (CurrentScratchReg == 0)
>>> +            const TargetRegisterInfo *TRI = Fn.getTarget().getRegisterInfo();
>>> +            BitVector Candidates(TRI->getNumRegs());
>>> +            RS->getRegsAvailable(RC, Candidates);
>>> +
>>> +            // If there are any registers available, use the one that's
>>> +            // unused for the longest after this instruction. That increases
>>> +            // the ability to reuse the value.
>>> +            if (Candidates.any()) {
>>> +              MachineBasicBlock::iterator UMI;
>>> +              CurrentScratchReg = RS->findSurvivorReg(I, Candidates, 25, UMI);
>>> +            } else {
>>>             // No register is "free". Scavenge a register.
>>>             CurrentScratchReg = RS->scavengeRegister(RC, I, SPAdj);
>>> +            }
>>> 
>>>           PrevValue = Value;
>>>         }
>> 
>> This looks like a method that escaped from RegScavenger. Isn't RegScavenger::scavengeRegister already doing this?
>> 
>> I think
>> 
>>              CurrentScratchReg = RS->scavengeRegister(RC, I, SPAdj);
>> 
>> is all you need.
>> 
>> 
> 
> It's close, but not quite. scavengeRegister() will find the register of the indicated register class that's used furthest away. It considers all registers of the register class as candidates, however, not just the available ones. Essentially, it's almost assuming that a spill will be required, but does have an early exit if for some reason it's called and finds a register that is available. That could just as easily be an assert, really.
> 
> Previously, we looked for an available register, taking the first one we noticed if one or more exists; otherwise, we called scavengeRegister() to find a reasonable choice to spill and free up a register to use. Now, we apply the same heuristic for "reasonable to use" to selecting amongst the available registers, not just when spilling.

Does it make sense to move the code into RS? Also, what's the magic number 25?

Evan

> 
> -Jim
> 
> 
> 
> 
> _______________________________________________
> llvm-commits mailing list
> llvm-commits at cs.uiuc.edu
> http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits



More information about the llvm-commits mailing list