[LLVMdev] Regalloc Refactoring

Chris Lattner sabre at nondot.org
Fri Apr 13 20:16:17 PDT 2007


On Thu, 12 Apr 2007, David Greene wrote:
>> Beyond that, one of the issues is the "r2rmap" and "rep" function.  As
>> you've noticed, the coallescer basically uses these to avoid rewriting the
>> code after it does coallescing.  For example, if r1024 is coallesced with
>> r1026, it leaves all uses of both registers in the code, instead of
>> rewriting uses of r1026 with r1024 and deleting all memory of r1026. This
>> mades sense long ago, but now it is increasingly clear that this is a bad
>> idea.  I would much rather have the coallescer be responsible for updating
>> the code.  I would suggest doing this as a first step, it is clearly
>> goodness :)
>
> This is what I was trying to get at, but wasn't entirely clear about.
> Does the loop nest after the call to joinIntervals  in
> LiveIntervals::runOnMachineFunction do this rewrite?

I didn't think anything did, but...

> Specifically:
>
>   // perform a final pass over the instructions and compute spill
>   // weights, coalesce virtual registers and remove identity moves.
>   const LoopInfo &loopInfo = getAnalysis<LoopInfo>();
>
>   for (MachineFunction::iterator mbbi = mf_->begin(), mbbe = mf_->end();
>        mbbi != mbbe; ++mbbi) {
>     [...]
>
>       for (unsigned i = 0, e = mii->getNumOperands(); i != e; ++i) {
>         const MachineOperand &mop = mii->getOperand(i);
>         if (mop.isRegister() && mop.getReg() &&
>             MRegisterInfo::isVirtualRegister(mop.getReg())) {
>           // replace register with representative register
>           unsigned reg = rep(mop.getReg());
>           mii->getOperand(i).setReg(reg);
>
> Doesn't that last statement actually do the rewrite?

Hrm, yes, yes it appears so.  Question is: doesn't this make the r2r map 
dead?  Does something else fill it in?  My memory is hazy here :).  If it 
is dead, we should rip it out (actually, we should make it private to the 
coallescer function).

> And how does this interact with the spill cost computation?  I'm 
> thinking separating out the spill cost computation is going to be a bit 
> more work because right now it does some of its calculations in concert 
> with this rewriting.  But it seems workable.

Makes sense to me.

>> Yes, but try to break this down into small pieces: first step is to
>> eliminate rep/r2rmap.  Second step is to split coallescer off.  PHI elim
>> changes are independent of this, but would also be a separate project.
>
> Good work plan.  That's how I'll submit the patches.

Great!

-Chris

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



More information about the llvm-dev mailing list