LLVM API Documentation

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
MSP430RegisterInfo.cpp
Go to the documentation of this file.
1 //===-- MSP430RegisterInfo.cpp - MSP430 Register Information --------------===//
2 //
3 // The LLVM Compiler Infrastructure
4 //
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
7 //
8 //===----------------------------------------------------------------------===//
9 //
10 // This file contains the MSP430 implementation of the TargetRegisterInfo class.
11 //
12 //===----------------------------------------------------------------------===//
13 
14 #define DEBUG_TYPE "msp430-reg-info"
15 
16 #include "MSP430RegisterInfo.h"
17 #include "MSP430.h"
19 #include "MSP430TargetMachine.h"
20 #include "llvm/ADT/BitVector.h"
24 #include "llvm/IR/Function.h"
28 
29 #define GET_REGINFO_TARGET_DESC
30 #include "MSP430GenRegisterInfo.inc"
31 
32 using namespace llvm;
33 
34 // FIXME: Provide proper call frame setup / destroy opcodes.
36  : MSP430GenRegisterInfo(MSP430::PCW), TM(tm) {
37  StackAlign = TM.getFrameLowering()->getStackAlignment();
38 }
39 
40 const uint16_t*
42  const TargetFrameLowering *TFI = MF->getTarget().getFrameLowering();
43  const Function* F = MF->getFunction();
44  static const uint16_t CalleeSavedRegs[] = {
45  MSP430::FPW, MSP430::R5W, MSP430::R6W, MSP430::R7W,
46  MSP430::R8W, MSP430::R9W, MSP430::R10W, MSP430::R11W,
47  0
48  };
49  static const uint16_t CalleeSavedRegsFP[] = {
50  MSP430::R5W, MSP430::R6W, MSP430::R7W,
51  MSP430::R8W, MSP430::R9W, MSP430::R10W, MSP430::R11W,
52  0
53  };
54  static const uint16_t CalleeSavedRegsIntr[] = {
55  MSP430::FPW, MSP430::R5W, MSP430::R6W, MSP430::R7W,
56  MSP430::R8W, MSP430::R9W, MSP430::R10W, MSP430::R11W,
57  MSP430::R12W, MSP430::R13W, MSP430::R14W, MSP430::R15W,
58  0
59  };
60  static const uint16_t CalleeSavedRegsIntrFP[] = {
61  MSP430::R5W, MSP430::R6W, MSP430::R7W,
62  MSP430::R8W, MSP430::R9W, MSP430::R10W, MSP430::R11W,
63  MSP430::R12W, MSP430::R13W, MSP430::R14W, MSP430::R15W,
64  0
65  };
66 
67  if (TFI->hasFP(*MF))
69  CalleeSavedRegsIntrFP : CalleeSavedRegsFP);
70  else
72  CalleeSavedRegsIntr : CalleeSavedRegs);
73 
74 }
75 
77  BitVector Reserved(getNumRegs());
79 
80  // Mark 4 special registers with subregisters as reserved.
81  Reserved.set(MSP430::PCB);
82  Reserved.set(MSP430::SPB);
83  Reserved.set(MSP430::SRB);
84  Reserved.set(MSP430::CGB);
85  Reserved.set(MSP430::PCW);
86  Reserved.set(MSP430::SPW);
87  Reserved.set(MSP430::SRW);
88  Reserved.set(MSP430::CGW);
89 
90  // Mark frame pointer as reserved if needed.
91  if (TFI->hasFP(MF))
92  Reserved.set(MSP430::FPW);
93 
94  return Reserved;
95 }
96 
97 const TargetRegisterClass *
99  const {
100  return &MSP430::GR16RegClass;
101 }
102 
103 void
105  int SPAdj, unsigned FIOperandNum,
106  RegScavenger *RS) const {
107  assert(SPAdj == 0 && "Unexpected");
108 
109  MachineInstr &MI = *II;
110  MachineBasicBlock &MBB = *MI.getParent();
111  MachineFunction &MF = *MBB.getParent();
112  const TargetFrameLowering *TFI = MF.getTarget().getFrameLowering();
113  DebugLoc dl = MI.getDebugLoc();
114  int FrameIndex = MI.getOperand(FIOperandNum).getIndex();
115 
116  unsigned BasePtr = (TFI->hasFP(MF) ? MSP430::FPW : MSP430::SPW);
117  int Offset = MF.getFrameInfo()->getObjectOffset(FrameIndex);
118 
119  // Skip the saved PC
120  Offset += 2;
121 
122  if (!TFI->hasFP(MF))
123  Offset += MF.getFrameInfo()->getStackSize();
124  else
125  Offset += 2; // Skip the saved FPW
126 
127  // Fold imm into offset
128  Offset += MI.getOperand(FIOperandNum + 1).getImm();
129 
130  if (MI.getOpcode() == MSP430::ADD16ri) {
131  // This is actually "load effective address" of the stack slot
132  // instruction. We have only two-address instructions, thus we need to
133  // expand it into mov + add
134  const TargetInstrInfo &TII = *MF.getTarget().getInstrInfo();
135 
136  MI.setDesc(TII.get(MSP430::MOV16rr));
137  MI.getOperand(FIOperandNum).ChangeToRegister(BasePtr, false);
138 
139  if (Offset == 0)
140  return;
141 
142  // We need to materialize the offset via add instruction.
143  unsigned DstReg = MI.getOperand(0).getReg();
144  if (Offset < 0)
145  BuildMI(MBB, llvm::next(II), dl, TII.get(MSP430::SUB16ri), DstReg)
146  .addReg(DstReg).addImm(-Offset);
147  else
148  BuildMI(MBB, llvm::next(II), dl, TII.get(MSP430::ADD16ri), DstReg)
149  .addReg(DstReg).addImm(Offset);
150 
151  return;
152  }
153 
154  MI.getOperand(FIOperandNum).ChangeToRegister(BasePtr, false);
155  MI.getOperand(FIOperandNum + 1).ChangeToImmediate(Offset);
156 }
157 
159  const TargetFrameLowering *TFI = MF.getTarget().getFrameLowering();
160 
161  return TFI->hasFP(MF) ? MSP430::FPW : MSP430::SPW;
162 }
const MachineFunction * getParent() const
BitVector & set()
Definition: BitVector.h:236
void ChangeToRegister(unsigned Reg, bool isDef, bool isImp=false, bool isKill=false, bool isDead=false, bool isUndef=false, bool isDebug=false)
F(f)
const Function * getFunction() const
CallingConv::ID getCallingConv() const
Definition: Function.h:161
uint64_t getStackSize() const
void eliminateFrameIndex(MachineBasicBlock::iterator II, int SPAdj, unsigned FIOperandNum, RegScavenger *RS=NULL) const
const HexagonInstrInfo * TII
virtual bool hasFP(const MachineFunction &MF) const =0
const MachineInstrBuilder & addImm(int64_t Val) const
int getOpcode() const
Definition: MachineInstr.h:261
int64_t getImm() const
void ChangeToImmediate(int64_t ImmVal)
const MachineBasicBlock * getParent() const
Definition: MachineInstr.h:119
bundle_iterator< MachineInstr, instr_iterator > iterator
BitVector getReservedRegs(const MachineFunction &MF) const
const MachineOperand & getOperand(unsigned i) const
Definition: MachineInstr.h:267
ItTy next(ItTy it, Dist n)
Definition: STLExtras.h:154
unsigned getFrameRegister(const MachineFunction &MF) const
MachineInstrBuilder BuildMI(MachineFunction &MF, DebugLoc DL, const MCInstrDesc &MCID)
MSP430_INTR - Calling convention used for MSP430 interrupt routines.
Definition: CallingConv.h:88
virtual const TargetFrameLowering * getFrameLowering() const
const MCInstrDesc & get(unsigned Opcode) const
Definition: MCInstrInfo.h:48
const TargetRegisterClass * getPointerRegClass(const MachineFunction &MF, unsigned Kind=0) const
int64_t getObjectOffset(int ObjectIdx) const
virtual const TargetInstrInfo * getInstrInfo() const
void setDesc(const MCInstrDesc &tid)
Definition: MachineInstr.h:984
MachineFrameInfo * getFrameInfo()
MSP430RegisterInfo(MSP430TargetMachine &tm)
const TargetMachine & getTarget() const
const uint16_t * getCalleeSavedRegs(const MachineFunction *MF=0) const
Code Generation virtual methods...
unsigned getReg() const
getReg - Returns the register number.
DebugLoc getDebugLoc() const
Definition: MachineInstr.h:244