Dear llvmers, I am trying to insert a move instruction where both source and destination registers are physical registers. How is the code for this? I tried this one here: void PhiDeconstruction_Fer::add_move ( MachineFunction & mf, MachineBasicBlock & mbb, unsigned src, unsigned dst ) { MachineBasicBlock::iterator iter = mbb.getFirstTerminator(); const TargetRegisterClass *rc = mf.getSSARegMap()->getRegClass(dst); const MRegisterInfo * reg_info = mf.getTarget().getRegisterInfo(); reg_info->copyRegToReg(mbb, iter, dst, src, rc); } But the getRegClass method seems to expect a virtual register. Could someone fix this code for me? I could not find an example in the source of LLVM. Thank you very much, Fernando
On Sun, 2 Jul 2006, Fernando Magno Quintao Pereira wrote:> MachineBasicBlock::iterator iter = mbb.getFirstTerminator(); > const TargetRegisterClass *rc = mf.getSSARegMap()->getRegClass(dst); > const MRegisterInfo * reg_info = mf.getTarget().getRegisterInfo(); > reg_info->copyRegToReg(mbb, iter, dst, src, rc); > } > > But the getRegClass method seems to expect a virtual register. Could > someone fix this code for me? I could not find an example in the source of > LLVM.You can't do it with this information. In some higher context you should have information about what register class the physreg is to be interpreted as. Physregs can be in multiple register classes. All of the register allocators call this method, so there are plenty of examples. -Chris -- http://nondot.org/sabre/ http://llvm.org/
> On Sun, 2 Jul 2006, Fernando Magno Quintao Pereira wrote: > > > MachineBasicBlock::iterator iter = mbb.getFirstTerminator(); > > const TargetRegisterClass *rc = mf.getSSARegMap()->getRegClass(dst); > > const MRegisterInfo * reg_info = mf.getTarget().getRegisterInfo(); > > reg_info->copyRegToReg(mbb, iter, dst, src, rc); > > } > > > > But the getRegClass method seems to expect a virtual register. Could > > someone fix this code for me? I could not find an example in the source of > > LLVM. > > You can't do it with this information. In some higher context you should > have information about what register class the physreg is to be > interpreted as. Physregs can be in multiple register classes. > > All of the register allocators call this method, so there are plenty of > examples. > > -ChrisThank you, chris. But I still do not understand how to insert this move instruction :) I have the machine function, the basic block, and the unsigned descriptors of the source and destiny register. With this information is possible to insert a move, considering that the source and destiny are physical registers? The example that I could find, in the phi-elimination pass, expects virtual registers. But I am eliminating phi functions after register allocation has been performed. I would like to know if there is a simple way to discover the class of a physical register given MachineFunction and MachineBasicBlock. Could you point me an example in the code of one of the register allocators? Thanks a lot, Fernando