LLVM API Documentation
00001 //===-- MSP430RegisterInfo.cpp - MSP430 Register Information --------------===// 00002 // 00003 // The LLVM Compiler Infrastructure 00004 // 00005 // This file is distributed under the University of Illinois Open Source 00006 // License. See LICENSE.TXT for details. 00007 // 00008 //===----------------------------------------------------------------------===// 00009 // 00010 // This file contains the MSP430 implementation of the TargetRegisterInfo class. 00011 // 00012 //===----------------------------------------------------------------------===// 00013 00014 #include "MSP430RegisterInfo.h" 00015 #include "MSP430.h" 00016 #include "MSP430MachineFunctionInfo.h" 00017 #include "MSP430TargetMachine.h" 00018 #include "llvm/ADT/BitVector.h" 00019 #include "llvm/CodeGen/MachineFrameInfo.h" 00020 #include "llvm/CodeGen/MachineFunction.h" 00021 #include "llvm/CodeGen/MachineInstrBuilder.h" 00022 #include "llvm/IR/Function.h" 00023 #include "llvm/Support/ErrorHandling.h" 00024 #include "llvm/Target/TargetMachine.h" 00025 #include "llvm/Target/TargetOptions.h" 00026 00027 using namespace llvm; 00028 00029 #define DEBUG_TYPE "msp430-reg-info" 00030 00031 #define GET_REGINFO_TARGET_DESC 00032 #include "MSP430GenRegisterInfo.inc" 00033 00034 // FIXME: Provide proper call frame setup / destroy opcodes. 00035 MSP430RegisterInfo::MSP430RegisterInfo() 00036 : MSP430GenRegisterInfo(MSP430::PC) {} 00037 00038 const MCPhysReg* 00039 MSP430RegisterInfo::getCalleeSavedRegs(const MachineFunction *MF) const { 00040 const TargetFrameLowering *TFI = MF->getSubtarget().getFrameLowering(); 00041 const Function* F = MF->getFunction(); 00042 static const MCPhysReg CalleeSavedRegs[] = { 00043 MSP430::FP, MSP430::R5, MSP430::R6, MSP430::R7, 00044 MSP430::R8, MSP430::R9, MSP430::R10, MSP430::R11, 00045 0 00046 }; 00047 static const MCPhysReg CalleeSavedRegsFP[] = { 00048 MSP430::R5, MSP430::R6, MSP430::R7, 00049 MSP430::R8, MSP430::R9, MSP430::R10, MSP430::R11, 00050 0 00051 }; 00052 static const MCPhysReg CalleeSavedRegsIntr[] = { 00053 MSP430::FP, MSP430::R5, MSP430::R6, MSP430::R7, 00054 MSP430::R8, MSP430::R9, MSP430::R10, MSP430::R11, 00055 MSP430::R12, MSP430::R13, MSP430::R14, MSP430::R15, 00056 0 00057 }; 00058 static const MCPhysReg CalleeSavedRegsIntrFP[] = { 00059 MSP430::R5, MSP430::R6, MSP430::R7, 00060 MSP430::R8, MSP430::R9, MSP430::R10, MSP430::R11, 00061 MSP430::R12, MSP430::R13, MSP430::R14, MSP430::R15, 00062 0 00063 }; 00064 00065 if (TFI->hasFP(*MF)) 00066 return (F->getCallingConv() == CallingConv::MSP430_INTR ? 00067 CalleeSavedRegsIntrFP : CalleeSavedRegsFP); 00068 else 00069 return (F->getCallingConv() == CallingConv::MSP430_INTR ? 00070 CalleeSavedRegsIntr : CalleeSavedRegs); 00071 00072 } 00073 00074 BitVector MSP430RegisterInfo::getReservedRegs(const MachineFunction &MF) const { 00075 BitVector Reserved(getNumRegs()); 00076 const TargetFrameLowering *TFI = MF.getSubtarget().getFrameLowering(); 00077 00078 // Mark 4 special registers with subregisters as reserved. 00079 Reserved.set(MSP430::PCB); 00080 Reserved.set(MSP430::SPB); 00081 Reserved.set(MSP430::SRB); 00082 Reserved.set(MSP430::CGB); 00083 Reserved.set(MSP430::PC); 00084 Reserved.set(MSP430::SP); 00085 Reserved.set(MSP430::SR); 00086 Reserved.set(MSP430::CG); 00087 00088 // Mark frame pointer as reserved if needed. 00089 if (TFI->hasFP(MF)) { 00090 Reserved.set(MSP430::FPB); 00091 Reserved.set(MSP430::FP); 00092 } 00093 00094 return Reserved; 00095 } 00096 00097 const TargetRegisterClass * 00098 MSP430RegisterInfo::getPointerRegClass(const MachineFunction &MF, unsigned Kind) 00099 const { 00100 return &MSP430::GR16RegClass; 00101 } 00102 00103 void 00104 MSP430RegisterInfo::eliminateFrameIndex(MachineBasicBlock::iterator II, 00105 int SPAdj, unsigned FIOperandNum, 00106 RegScavenger *RS) const { 00107 assert(SPAdj == 0 && "Unexpected"); 00108 00109 MachineInstr &MI = *II; 00110 MachineBasicBlock &MBB = *MI.getParent(); 00111 MachineFunction &MF = *MBB.getParent(); 00112 const TargetFrameLowering *TFI = MF.getSubtarget().getFrameLowering(); 00113 DebugLoc dl = MI.getDebugLoc(); 00114 int FrameIndex = MI.getOperand(FIOperandNum).getIndex(); 00115 00116 unsigned BasePtr = (TFI->hasFP(MF) ? MSP430::FP : MSP430::SP); 00117 int Offset = MF.getFrameInfo()->getObjectOffset(FrameIndex); 00118 00119 // Skip the saved PC 00120 Offset += 2; 00121 00122 if (!TFI->hasFP(MF)) 00123 Offset += MF.getFrameInfo()->getStackSize(); 00124 else 00125 Offset += 2; // Skip the saved FP 00126 00127 // Fold imm into offset 00128 Offset += MI.getOperand(FIOperandNum + 1).getImm(); 00129 00130 if (MI.getOpcode() == MSP430::ADD16ri) { 00131 // This is actually "load effective address" of the stack slot 00132 // instruction. We have only two-address instructions, thus we need to 00133 // expand it into mov + add 00134 const TargetInstrInfo &TII = *MF.getSubtarget().getInstrInfo(); 00135 00136 MI.setDesc(TII.get(MSP430::MOV16rr)); 00137 MI.getOperand(FIOperandNum).ChangeToRegister(BasePtr, false); 00138 00139 if (Offset == 0) 00140 return; 00141 00142 // We need to materialize the offset via add instruction. 00143 unsigned DstReg = MI.getOperand(0).getReg(); 00144 if (Offset < 0) 00145 BuildMI(MBB, std::next(II), dl, TII.get(MSP430::SUB16ri), DstReg) 00146 .addReg(DstReg).addImm(-Offset); 00147 else 00148 BuildMI(MBB, std::next(II), dl, TII.get(MSP430::ADD16ri), DstReg) 00149 .addReg(DstReg).addImm(Offset); 00150 00151 return; 00152 } 00153 00154 MI.getOperand(FIOperandNum).ChangeToRegister(BasePtr, false); 00155 MI.getOperand(FIOperandNum + 1).ChangeToImmediate(Offset); 00156 } 00157 00158 unsigned MSP430RegisterInfo::getFrameRegister(const MachineFunction &MF) const { 00159 const TargetFrameLowering *TFI = MF.getSubtarget().getFrameLowering(); 00160 00161 return TFI->hasFP(MF) ? MSP430::FP : MSP430::SP; 00162 }