How to access Target Register Info?

I am writing a register renaming pass for loops. I want to printout livein variables at a specific basic block and find a registerset A = target register - livein regs.
I am using the following code

for (MachineBasicBlock::livein_iterator LI = mb->livein_begin(), E = mb->livein_end(); LI != E; ++LI){
const TargetRegisterInfo *TRI = MF.getTarget().getRegisterInfo();

errs() << ’ ’ << PrintReg(*LI, TRI);


but I get the following error:
error: member access into incomplete type ‘const llvm::TargetMachine’ const TargetRegisterInfo *TRI = MF.getTarget().getRegisterInfo(); ^ /home/lab154/fateme/LLVM/llvm-3.7/include/llvm/CodeGen/MachineOperand.h:31:7: note: forward declaration of ‘llvm::TargetMachine’ class TargetMachine;

So what is the correct way to access TRI?
Also, I know that ARM has 13 GPRs (r0-r12). but how to get this from the code?
I am sorry if my questions are stupid, but spend a lot of time on them and did not find the solution.


TargetRegisterInfo is now in the TargetSubtargetInfo. So you need to do
   auto *TRI = MF.getSubtarget<yourtarget>().getRegisterInfo();