1 //===- PIC16RegisterInfo.cpp - PIC16 Register Information -----------------===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 // This file contains the PIC16 implementation of the TargetRegisterInfo class.
12 //===----------------------------------------------------------------------===//
14 #define DEBUG_TYPE "pic16-reg-info"
17 #include "PIC16RegisterInfo.h"
18 #include "llvm/Constants.h"
19 #include "llvm/Function.h"
20 #include "llvm/Type.h"
21 #include "llvm/ADT/BitVector.h"
22 #include "llvm/ADT/STLExtras.h"
23 #include "llvm/CodeGen/MachineFrameInfo.h"
24 #include "llvm/CodeGen/MachineFunction.h"
25 #include "llvm/CodeGen/MachineInstrBuilder.h"
26 #include "llvm/CodeGen/MachineLocation.h"
27 #include "llvm/CodeGen/ValueTypes.h"
28 #include "llvm/Support/CommandLine.h"
29 #include "llvm/Support/Debug.h"
30 #include "llvm/Target/TargetFrameInfo.h"
31 #include "llvm/Target/TargetInstrInfo.h"
32 #include "llvm/Target/TargetMachine.h"
33 #include "llvm/Target/TargetOptions.h"
37 // TODO: add subtarget support
38 PIC16RegisterInfo::PIC16RegisterInfo(const TargetInstrInfo &tii)
39 : PIC16GenRegisterInfo(PIC16::ADJCALLSTACKDOWN, PIC16::ADJCALLSTACKUP),
42 /// getRegisterNumbering - Given the enum value for some register, e.g.
43 /// PIC16::RA, return the number that it corresponds to (e.g. 31).
44 unsigned PIC16RegisterInfo::
45 getRegisterNumbering(unsigned RegEnum)
47 assert (RegEnum <= 31 && "Unknown register number!");
51 void PIC16RegisterInfo::
52 copyRegToReg(MachineBasicBlock &MBB, MachineBasicBlock::iterator I,
53 unsigned DestReg, unsigned SrcReg,
54 const TargetRegisterClass *RC) const
59 void PIC16RegisterInfo::reMaterialize(MachineBasicBlock &MBB,
60 MachineBasicBlock::iterator I,
62 const MachineInstr *Orig) const
64 MachineInstr *MI = Orig->clone();
65 MI->getOperand(0).setReg(DestReg);
69 MachineInstr *PIC16RegisterInfo::
70 foldMemoryOperand(MachineInstr* MI, unsigned OpNum, int FI) const
72 MachineInstr *NewMI = NULL;
77 //===----------------------------------------------------------------------===//
79 // Callee Saved Registers methods
81 //===----------------------------------------------------------------------===//
83 /// PIC16 Callee Saved Registers
84 const unsigned* PIC16RegisterInfo::
85 getCalleeSavedRegs(const MachineFunction *MF) const
87 // PIC16 calle-save register range is $16-$26(s0-s7)
88 static const unsigned CalleeSavedRegs[] = { 0 };
89 return CalleeSavedRegs;
92 /// PIC16 Callee Saved Register Classes
93 const TargetRegisterClass* const*
94 PIC16RegisterInfo::getCalleeSavedRegClasses(const MachineFunction *MF) const
96 static const TargetRegisterClass * const CalleeSavedRegClasses[] = { 0 };
97 return CalleeSavedRegClasses;
100 BitVector PIC16RegisterInfo::
101 getReservedRegs(const MachineFunction &MF) const
103 BitVector Reserved(getNumRegs());
107 //===----------------------------------------------------------------------===//
109 // Stack Frame Processing methods
110 // +----------------------------+
112 // FIXME: Add stack layout description here.
115 //===----------------------------------------------------------------------===//
117 // hasFP - Return true if the specified function should have a dedicated frame
118 // pointer register. This is true if the function has variable sized allocas or
119 // if frame pointer elimination is disabled.
120 bool PIC16RegisterInfo::
121 hasFP(const MachineFunction &MF) const {
125 // This function eliminate ADJCALLSTACKDOWN,
126 // ADJCALLSTACKUP pseudo instructions
127 void PIC16RegisterInfo::
128 eliminateCallFramePseudoInstr(MachineFunction &MF, MachineBasicBlock &MBB,
129 MachineBasicBlock::iterator I) const {
130 // Simply discard ADJCALLSTACKDOWN, ADJCALLSTACKUP instructions.
134 // FrameIndex represent objects inside a abstract stack.
135 // We must replace FrameIndex with an stack/frame pointer
137 void PIC16RegisterInfo::
138 eliminateFrameIndex(MachineBasicBlock::iterator II, int SPAdj,
139 RegScavenger *RS) const
141 MachineInstr &MI = *II;
142 MachineFunction &MF = *MI.getParent()->getParent();
145 while (!MI.getOperand(i).isFrameIndex()) {
147 assert(i < MI.getNumOperands() &&
148 "Instr doesn't have FrameIndex operand!");
151 int FrameIndex = MI.getOperand(i).getIndex();
152 int stackSize = MF.getFrameInfo()->getStackSize();
153 int spOffset = MF.getFrameInfo()->getObjectOffset(FrameIndex);
156 DOUT << "\nFunction : " << MF.getFunction()->getName() << "\n";
157 DOUT << "<--------->\n";
159 DOUT << "FrameIndex : " << FrameIndex << "\n";
160 DOUT << "spOffset : " << spOffset << "\n";
161 DOUT << "stackSize : " << stackSize << "\n";
164 // as explained on LowerFORMAL_ARGUMENTS, detect negative offsets
165 // and adjust SPOffsets considering the final stack size.
166 int Offset = ((spOffset < 0) ? (stackSize + (-(spOffset+4))) : (spOffset));
167 //Offset += MI.getOperand(i+1).getImm();
170 DOUT << "Offset : " << Offset << "\n";
171 DOUT << "<--------->\n";
174 // MI.getOperand(i+1).ChangeToImmediate(Offset);
175 MI.getOperand(i).ChangeToRegister(getFrameRegister(MF),false);
178 void PIC16RegisterInfo::
179 emitPrologue(MachineFunction &MF) const
183 void PIC16RegisterInfo::
184 emitEpilogue(MachineFunction &MF, MachineBasicBlock &MBB) const
188 void PIC16RegisterInfo::
189 processFunctionBeforeFrameFinalized(MachineFunction &MF) const {
192 unsigned PIC16RegisterInfo::
193 getRARegister() const {
194 assert(0 && "What is the return address register");
198 unsigned PIC16RegisterInfo::
199 getFrameRegister(MachineFunction &MF) const {
200 return PIC16::STKPTR;
203 unsigned PIC16RegisterInfo::
204 getEHExceptionRegister() const {
205 assert(0 && "What is the exception register");
209 unsigned PIC16RegisterInfo::
210 getEHHandlerRegister() const {
211 assert(0 && "What is the exception handler register");
215 int PIC16RegisterInfo::
216 getDwarfRegNum(unsigned RegNum, bool isEH) const {
217 assert(0 && "What is the dwarf register number");
222 #include "PIC16GenRegisterInfo.inc"