2015年8月30日 星期日

RegisterAllocation2

In the First scan, try to find the direct use of physics register and define it. If the number of physical registers are enough for using in the instruction, it is clear that these physical registers are defined and the live unit can be calculated. In the first scan, the count of number virtual registers is also performed.

00930       if (TargetRegisterInfo::isVirtualRegister(Reg)) {
00931         VirtOpEnd = i+1;
00932         if (MO.isUse()) {
00933           hasTiedOps = hasTiedOps ||
00934                               MCID.getOperandConstraint(i, MCOI::TIED_TO) != -1;
00935         } else {
00936           if (MO.isEarlyClobber())
00937             hasEarlyClobbers = true;
00938           if (MO.getSubReg() && MI->readsVirtualRegister(Reg))
00939             hasPartialRedefs = true;
00940         }
00941         continue;
00942       }

 IN THE Second scan, it would determine on the registers whether they are used are not. If the virtual register is used and the virtual register is new,    it should try to load the frame index from the stack.

RAFast::reloadVirtualReg
00631   if (New) {
00632     LRI = allocVirtReg(MI, LRI, Hint);
00633     const TargetRegisterClass *RC = MRI->getRegClass(VirtReg);
00634     int FrameIndex = getStackSpaceFor(VirtReg, RC);
00635     DEBUG(dbgs() << "Reloading " << PrintReg(VirtReg, TRI) << " into "
00636                  << PrintReg(LRI->PhysReg, TRI) << "\n");
00637     TII->loadRegFromStackSlot(*MBB, MI, LRI->PhysReg, FrameIndex, RC, TRI);
00638     ++NumLoads;
00639   } else if (LRI->Dirty) {

  
 In the third scan, it would focus on the defs which is possible virtual register or physical register. In the beginning of the for loop, it tries to find the defs which are not deal with. If there are virtual registers it would defineVirtReg and

in the defineVirtReg it will call the definePhysicReg finally, otherwise, it will call definePhysReg as they are physical regiters.

01025     for (unsigned i = 0; i != DefOpEnd; ++i) {
01026       MachineOperand &MO = MI->getOperand(i);
01027       if (!MO.isReg() || !MO.isDef() || !MO.getReg() || MO.isEarlyClobber())
01028         continue;
01029       unsigned Reg = MO.getReg();
01030 
01031       if (TargetRegisterInfo::isPhysicalRegister(Reg)) {
01032         if (!MRI->isAllocatable(Reg)) continue;
01033         definePhysReg(MI, Reg, MO.isDead() ? regFree : regReserved);
01034         continue;
01035       }
01036       LiveRegMap::iterator LRI = defineVirtReg(MI, i, Reg, CopySrc);
01037       unsigned PhysReg = LRI->PhysReg;
01038       if (setPhysReg(MI, i, PhysReg)) {
01039         VirtDead.push_back(Reg);
01040         CopyDst = 0; // cancel coalescing;
01041       } else
01042         CopyDst = (CopyDst == Reg || CopyDst == PhysReg) ? PhysReg : 0;
01043     }

沒有留言:

張貼留言