Adding files for Microchip's PIC16 target.
[oota-llvm.git] / lib / Target / PIC16 / PIC16RegisterInfo.cpp
1 //===- PIC16RegisterInfo.cpp - PIC16 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 PIC16 implementation of the TargetRegisterInfo class.
11 //
12 //===----------------------------------------------------------------------===//
13
14 #define DEBUG_TYPE "pic16-reg-info"
15
16 #include "PIC16.h"
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"
34
35 using namespace llvm;
36
37 // TODO: add subtarget support
38 PIC16RegisterInfo::PIC16RegisterInfo(const TargetInstrInfo &tii)
39   : PIC16GenRegisterInfo(PIC16::ADJCALLSTACKDOWN, PIC16::ADJCALLSTACKUP),
40   TII(tii) {}
41
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) 
46 {
47    assert (RegEnum <= 31 && "Unknown register number!");
48    return RegEnum;
49 }
50
51 void PIC16RegisterInfo::
52 copyRegToReg(MachineBasicBlock &MBB, MachineBasicBlock::iterator I,
53              unsigned DestReg, unsigned SrcReg,
54              const TargetRegisterClass *RC) const 
55 {
56   return;
57 }
58
59 void PIC16RegisterInfo::reMaterialize(MachineBasicBlock &MBB, 
60                                       MachineBasicBlock::iterator I,
61                                       unsigned DestReg, 
62                                       const MachineInstr *Orig) const 
63 {
64     MachineInstr *MI = Orig->clone();
65     MI->getOperand(0).setReg(DestReg);
66     MBB.insert(I, MI);
67 }
68
69 MachineInstr *PIC16RegisterInfo::
70 foldMemoryOperand(MachineInstr* MI, unsigned OpNum, int FI) const 
71 {
72   MachineInstr *NewMI = NULL;
73
74   return NewMI;
75 }
76
77 //===----------------------------------------------------------------------===//
78 //
79 // Callee Saved Registers methods 
80 //
81 //===----------------------------------------------------------------------===//
82
83 /// PIC16 Callee Saved Registers
84 const unsigned* PIC16RegisterInfo::
85 getCalleeSavedRegs(const MachineFunction *MF) const 
86 {
87   // PIC16 calle-save register range is $16-$26(s0-s7)
88   static const unsigned CalleeSavedRegs[] = { 0 };
89   return CalleeSavedRegs;
90 }
91
92 /// PIC16 Callee Saved Register Classes
93 const TargetRegisterClass* const* 
94 PIC16RegisterInfo::getCalleeSavedRegClasses(const MachineFunction *MF) const 
95 {
96   static const TargetRegisterClass * const CalleeSavedRegClasses[] = { 0 };
97   return CalleeSavedRegClasses;
98 }
99
100 BitVector PIC16RegisterInfo::
101 getReservedRegs(const MachineFunction &MF) const
102 {
103   BitVector Reserved(getNumRegs());
104   return Reserved;
105 }
106
107 //===----------------------------------------------------------------------===//
108 //
109 // Stack Frame Processing methods
110 // +----------------------------+
111 //
112 // FIXME: Add stack layout description here.
113 //
114 //
115 //===----------------------------------------------------------------------===//
116
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 {
122   return false;
123 }
124
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.
131   MBB.erase(I);
132 }
133
134 // FrameIndex represent objects inside a abstract stack.
135 // We must replace FrameIndex with an stack/frame pointer
136 // direct reference.
137 void PIC16RegisterInfo::
138 eliminateFrameIndex(MachineBasicBlock::iterator II, int SPAdj, 
139                     RegScavenger *RS) const 
140 {
141   MachineInstr &MI    = *II;
142   MachineFunction &MF = *MI.getParent()->getParent();
143
144   unsigned i = 0;
145   while (!MI.getOperand(i).isFrameIndex()) {
146     ++i;
147     assert(i < MI.getNumOperands() && 
148            "Instr doesn't have FrameIndex operand!");
149   }
150
151   int FrameIndex = MI.getOperand(i).getIndex();
152   int stackSize  = MF.getFrameInfo()->getStackSize();
153   int spOffset   = MF.getFrameInfo()->getObjectOffset(FrameIndex);
154
155   #ifndef NDEBUG
156   DOUT << "\nFunction : " << MF.getFunction()->getName() << "\n";
157   DOUT << "<--------->\n";
158   MI.print(DOUT);
159   DOUT << "FrameIndex : " << FrameIndex << "\n";
160   DOUT << "spOffset   : " << spOffset << "\n";
161   DOUT << "stackSize  : " << stackSize << "\n";
162   #endif
163
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();
168
169   #ifndef NDEBUG
170   DOUT << "Offset     : " << Offset << "\n";
171   DOUT << "<--------->\n";
172   #endif
173
174   // MI.getOperand(i+1).ChangeToImmediate(Offset);
175    MI.getOperand(i).ChangeToRegister(getFrameRegister(MF),false);
176 }
177
178 void PIC16RegisterInfo::
179 emitPrologue(MachineFunction &MF) const 
180 {
181 }
182
183 void PIC16RegisterInfo::
184 emitEpilogue(MachineFunction &MF, MachineBasicBlock &MBB) const 
185 {
186 }
187
188 void PIC16RegisterInfo::
189 processFunctionBeforeFrameFinalized(MachineFunction &MF) const {
190 }
191
192 unsigned PIC16RegisterInfo::
193 getRARegister() const {
194   assert(0 && "What is the return address register");
195   return 0;
196 }
197
198 unsigned PIC16RegisterInfo::
199 getFrameRegister(MachineFunction &MF) const {
200   return PIC16::STKPTR;
201 }
202
203 unsigned PIC16RegisterInfo::
204 getEHExceptionRegister() const {
205   assert(0 && "What is the exception register");
206   return 0;
207 }
208
209 unsigned PIC16RegisterInfo::
210 getEHHandlerRegister() const {
211   assert(0 && "What is the exception handler register");
212   return 0;
213 }
214
215 int PIC16RegisterInfo::
216 getDwarfRegNum(unsigned RegNum, bool isEH) const {
217   assert(0 && "What is the dwarf register number");
218   return -1;
219 }
220
221
222 #include "PIC16GenRegisterInfo.inc"
223