2015年9月13日 星期日

  RAFast::allocVirtReg is the way to allocate the virtual register to physical register in defineVirtReg. In the definVirtReg, when the virtual register is the new one in live interval, it is necessary to allocate the physical register to the virtual register. Therefore, the aim of allocVirtReg is to find the accessible physical register and allocate to it.

  Firstly, in the RAFast::allocVirtReg, it should find the target register class which has the same kind of registers.  Machine Register Information class is designed to provide the information of the registers. 

  const TargetRegisterClass * rc = MRI->getRegClass(VirtReg);

  It means that MRI has the map from virtual register to some identical register class
in the register class, it has many same functional registers, such as (EAX, EBX, EDX, are all 32 bit registers). TargetRegisterClass has the iterator for the begin machine register and the final machine register. 
   
  Otherwise, the target register info has many register class, because the registers in every different platform are categoried by the class in the LLVM. It means that the same registers (same function, 32 bits for example )are in the same group. Virtual registers are different by their targets (32 bit or 8 bits), it could be allocated by the MRI depended on the their function. Therefore, the 32 bits virtual registers are only could be allocated to the 32 bits physical registers.
  
  

 The hint in the allocVirtReg is the physical register, the free is determined in the allocateBasicblock. Therefore, the hint can be used directly, when the hint is valid. The hint is possible the target register, we have to calculate the spillcost of the hint. 

There are three different result:

Firstly, if the hint is not dirty register, than the definePhyReg is used to allocate the physical register.

Second, we try to find the free register and allocate it to the virtual register.


Third, the program scan all the registers and calculate the cost all the registers which find the lowest spill cost and allocate the physical register which has lowest spill cost to the virtual register.




沒有留言:

張貼留言