Expose base register for DwarfWriter. Refactor code accordingly.
[oota-llvm.git] / lib / Target / SparcV9 / SparcV9RegisterInfo.cpp
1 //===- SparcV9RegisterInfo.cpp - SparcV9 Register Information ---*- C++ -*-===//
2 //
3 //                     The LLVM Compiler Infrastructure
4 //
5 // This file was developed by the LLVM research group and is distributed under
6 // the University of Illinois Open Source License. See LICENSE.TXT for details.
7 //
8 //===----------------------------------------------------------------------===//
9 //
10 // This file contains the SparcV9 implementation of the MRegisterInfo class.
11 // It also contains stuff needed to instantiate that class, which would
12 // ordinarily be provided by TableGen.
13 //
14 // This is NOT used by the SparcV9 backend to do register allocation, yet.
15 //
16 //===----------------------------------------------------------------------===//
17 //
18 // The first section of this file (immediately following) is what
19 // you would find in SparcV9GenRegisterInfo.inc, if we were using
20 // TableGen to generate the register file description automatically.
21 // It consists of register classes and register class instances
22 // for the SparcV9 target.
23 //
24 // FIXME: the alignments listed here are wild guesses.
25 //
26 //===----------------------------------------------------------------------===//
27
28 #include "SparcV9RegisterInfo.h"
29 #include "llvm/CodeGen/MachineFunction.h"
30 #include "llvm/CodeGen/ValueTypes.h"
31 using namespace llvm;
32
33 namespace llvm {
34
35 namespace {
36   // IR Register Class...
37   const unsigned IR[] = {
38     SparcV9::o0, SparcV9::o1, SparcV9::o2, SparcV9::o3, SparcV9::o4,
39     SparcV9::o5, SparcV9::o7, SparcV9::l0, SparcV9::l1, SparcV9::l2,
40     SparcV9::l3, SparcV9::l4, SparcV9::l5, SparcV9::l6, SparcV9::l7,
41     SparcV9::i0, SparcV9::i1, SparcV9::i2, SparcV9::i3, SparcV9::i4,
42     SparcV9::i5, SparcV9::i6, SparcV9::i7, SparcV9::g0, SparcV9::g1,
43     SparcV9::g2, SparcV9::g3, SparcV9::g4, SparcV9::g5, SparcV9::g6,
44     SparcV9::g7, SparcV9::o6
45   };
46   const MVT::ValueType IRVTs[] = { MVT::i64, MVT::Other };
47   struct IRClass : public TargetRegisterClass {
48     IRClass() : TargetRegisterClass(IRVTs, 8, 8, IR, IR + 32) {}
49   } IRInstance;
50
51
52   // FR Register Class...
53   const unsigned FR[] = {
54     SparcV9::f0, SparcV9::f1, SparcV9::f2, SparcV9::f3, SparcV9::f4,
55     SparcV9::f5, SparcV9::f6, SparcV9::f7, SparcV9::f8, SparcV9::f9,
56     SparcV9::f10, SparcV9::f11, SparcV9::f12, SparcV9::f13,
57     SparcV9::f14, SparcV9::f15, SparcV9::f16, SparcV9::f17,
58     SparcV9::f18, SparcV9::f19, SparcV9::f20, SparcV9::f21,
59     SparcV9::f22, SparcV9::f23, SparcV9::f24, SparcV9::f25,
60     SparcV9::f26, SparcV9::f27, SparcV9::f28, SparcV9::f29,
61     SparcV9::f30, SparcV9::f31, SparcV9::f32, SparcV9::f33,
62     SparcV9::f34, SparcV9::f35, SparcV9::f36, SparcV9::f37,
63     SparcV9::f38, SparcV9::f39, SparcV9::f40, SparcV9::f41,
64     SparcV9::f42, SparcV9::f43, SparcV9::f44, SparcV9::f45,
65     SparcV9::f46, SparcV9::f47, SparcV9::f48, SparcV9::f49,
66     SparcV9::f50, SparcV9::f51, SparcV9::f52, SparcV9::f53,
67     SparcV9::f54, SparcV9::f55, SparcV9::f56, SparcV9::f57,
68     SparcV9::f58, SparcV9::f59, SparcV9::f60, SparcV9::f61,
69     SparcV9::f62, SparcV9::f63
70   };
71   const MVT::ValueType FRVTs[] = { MVT::f32, MVT::Other };
72   // FIXME: The size is correct for the first 32 registers. The
73   // latter 32 do not all really exist; you can only access every other
74   // one (32, 34, ...), and they must contain double-fp or quad-fp
75   // values... see below about the aliasing problems.
76   struct FRClass : public TargetRegisterClass {
77     FRClass() : TargetRegisterClass(FRVTs, 4, 8, FR, FR + 64) {}
78   } FRInstance;
79
80
81   // ICCR Register Class...
82   const unsigned ICCR[] = {
83     SparcV9::xcc, SparcV9::icc, SparcV9::ccr
84   };
85   const MVT::ValueType ICCRVTs[] = { MVT::i1, MVT::Other };
86   struct ICCRClass : public TargetRegisterClass {
87     ICCRClass() : TargetRegisterClass(ICCRVTs, 1, 8, ICCR, ICCR + 3) {}
88   } ICCRInstance;
89
90
91   // FCCR Register Class...
92   const unsigned FCCR[] = {
93     SparcV9::fcc0, SparcV9::fcc1, SparcV9::fcc2, SparcV9::fcc3
94   };
95   const MVT::ValueType FCCRVTs[] = { MVT::i1, MVT::Other };
96   struct FCCRClass : public TargetRegisterClass {
97     FCCRClass() : TargetRegisterClass(FCCRVTs, 1, 8, FCCR, FCCR + 4) {}
98   } FCCRInstance;
99
100
101   // SR Register Class...
102   const unsigned SR[] = {
103     SparcV9::fsr
104   };
105   const MVT::ValueType SRVTs[] = { MVT::i64, MVT::Other };
106   struct SRClass : public TargetRegisterClass {
107     SRClass() : TargetRegisterClass(SRVTs, 8, 8, SR, SR + 1) {}
108   } SRInstance;
109
110
111   // Register Classes...
112   const TargetRegisterClass* const RegisterClasses[] = {
113     &IRInstance,
114     &FRInstance,
115     &ICCRInstance,
116     &FCCRInstance,
117     &SRInstance
118   };
119
120
121   // Register Alias Sets...
122   // FIXME: Note that the SparcV9 backend does not currently abstract
123   // very well over the way that double-fp and quad-fp values may alias
124   // single-fp values in registers. Therefore those aliases are NOT
125   // reflected here.
126   const unsigned Empty_AliasSet[] = { 0 };
127   const unsigned fcc3_AliasSet[] = { SparcV9::fsr, 0 };
128   const unsigned fcc2_AliasSet[] = { SparcV9::fsr, 0 };
129   const unsigned fcc1_AliasSet[] = { SparcV9::fsr, 0 };
130   const unsigned fcc0_AliasSet[] = { SparcV9::fsr, 0 };
131   const unsigned fsr_AliasSet[] = { SparcV9::fcc3, SparcV9::fcc2,
132                                     SparcV9::fcc1, SparcV9::fcc0, 0 };
133   const unsigned xcc_AliasSet[] = { SparcV9::ccr, 0 };
134   const unsigned icc_AliasSet[] = { SparcV9::ccr, 0 };
135   const unsigned ccr_AliasSet[] = { SparcV9::xcc, SparcV9::icc, 0 };
136
137 const TargetRegisterDesc RegisterDescriptors[] = { // Descriptors
138   { "o0", Empty_AliasSet },
139   { "o1", Empty_AliasSet },
140   { "o2", Empty_AliasSet },
141   { "o3", Empty_AliasSet },
142   { "o4", Empty_AliasSet },
143   { "o5", Empty_AliasSet },
144   { "o7", Empty_AliasSet },
145   { "l0", Empty_AliasSet },
146   { "l1", Empty_AliasSet },
147   { "l2", Empty_AliasSet },
148   { "l3", Empty_AliasSet },
149   { "l4", Empty_AliasSet },
150   { "l5", Empty_AliasSet },
151   { "l6", Empty_AliasSet },
152   { "l7", Empty_AliasSet },
153   { "i0", Empty_AliasSet },
154   { "i1", Empty_AliasSet },
155   { "i2", Empty_AliasSet },
156   { "i3", Empty_AliasSet },
157   { "i4", Empty_AliasSet },
158   { "i5", Empty_AliasSet },
159   { "i6", Empty_AliasSet },
160   { "i7", Empty_AliasSet },
161   { "g0", Empty_AliasSet },
162   { "g1", Empty_AliasSet },
163   { "g2", Empty_AliasSet },
164   { "g3", Empty_AliasSet },
165   { "g4", Empty_AliasSet },
166   { "g5", Empty_AliasSet },
167   { "g6", Empty_AliasSet },
168   { "g7", Empty_AliasSet },
169   { "o6", Empty_AliasSet },
170   { "f0", Empty_AliasSet },
171   { "f1", Empty_AliasSet },
172   { "f2", Empty_AliasSet },
173   { "f3", Empty_AliasSet },
174   { "f4", Empty_AliasSet },
175   { "f5", Empty_AliasSet },
176   { "f6", Empty_AliasSet },
177   { "f7", Empty_AliasSet },
178   { "f8", Empty_AliasSet },
179   { "f9", Empty_AliasSet },
180   { "f10", Empty_AliasSet },
181   { "f11", Empty_AliasSet },
182   { "f12", Empty_AliasSet },
183   { "f13", Empty_AliasSet },
184   { "f14", Empty_AliasSet },
185   { "f15", Empty_AliasSet },
186   { "f16", Empty_AliasSet },
187   { "f17", Empty_AliasSet },
188   { "f18", Empty_AliasSet },
189   { "f19", Empty_AliasSet },
190   { "f20", Empty_AliasSet },
191   { "f21", Empty_AliasSet },
192   { "f22", Empty_AliasSet },
193   { "f23", Empty_AliasSet },
194   { "f24", Empty_AliasSet },
195   { "f25", Empty_AliasSet },
196   { "f26", Empty_AliasSet },
197   { "f27", Empty_AliasSet },
198   { "f28", Empty_AliasSet },
199   { "f29", Empty_AliasSet },
200   { "f30", Empty_AliasSet },
201   { "f31", Empty_AliasSet },
202   { "f32", Empty_AliasSet },
203   { "f33", Empty_AliasSet },
204   { "f34", Empty_AliasSet },
205   { "f35", Empty_AliasSet },
206   { "f36", Empty_AliasSet },
207   { "f37", Empty_AliasSet },
208   { "f38", Empty_AliasSet },
209   { "f39", Empty_AliasSet },
210   { "f40", Empty_AliasSet },
211   { "f41", Empty_AliasSet },
212   { "f42", Empty_AliasSet },
213   { "f43", Empty_AliasSet },
214   { "f44", Empty_AliasSet },
215   { "f45", Empty_AliasSet },
216   { "f46", Empty_AliasSet },
217   { "f47", Empty_AliasSet },
218   { "f48", Empty_AliasSet },
219   { "f49", Empty_AliasSet },
220   { "f50", Empty_AliasSet },
221   { "f51", Empty_AliasSet },
222   { "f52", Empty_AliasSet },
223   { "f53", Empty_AliasSet },
224   { "f54", Empty_AliasSet },
225   { "f55", Empty_AliasSet },
226   { "f56", Empty_AliasSet },
227   { "f57", Empty_AliasSet },
228   { "f58", Empty_AliasSet },
229   { "f59", Empty_AliasSet },
230   { "f60", Empty_AliasSet },
231   { "f61", Empty_AliasSet },
232   { "f62", Empty_AliasSet },
233   { "f63", Empty_AliasSet },
234   { "xcc", xcc_AliasSet },
235   { "icc", icc_AliasSet },
236   { "ccr", ccr_AliasSet },
237   { "fcc0", fcc0_AliasSet },
238   { "fcc1", fcc1_AliasSet },
239   { "fcc2", fcc2_AliasSet },
240   { "fcc3", fcc3_AliasSet },
241   { "fsr", fsr_AliasSet },
242 };
243
244 } // end anonymous namespace
245
246 namespace SparcV9 { // Register classes
247   TargetRegisterClass *IRRegisterClass = &IRInstance;
248   TargetRegisterClass *FRRegisterClass = &FRInstance;
249   TargetRegisterClass *ICCRRegisterClass = &ICCRInstance;
250   TargetRegisterClass *FCCRRegisterClass = &FCCRInstance;
251   TargetRegisterClass *SRRegisterClass = &SRInstance;
252 } // end namespace SparcV9
253
254 const unsigned *SparcV9RegisterInfo::getCalleeSaveRegs() const {
255   // FIXME: This should be verified against the SparcV9 ABI at some point.
256   // These are the registers which the SparcV9 backend considers
257   // "non-volatile".
258   static const unsigned CalleeSaveRegs[] = {
259      SparcV9::l0, SparcV9::l1, SparcV9::l2, SparcV9::l3, SparcV9::l4,
260      SparcV9::l5, SparcV9::l6, SparcV9::l7, SparcV9::i0, SparcV9::i1,
261      SparcV9::i2, SparcV9::i3, SparcV9::i4, SparcV9::i5, SparcV9::i6,
262      SparcV9::i7, SparcV9::g0, SparcV9::g1, SparcV9::g2, SparcV9::g3,
263      SparcV9::g4, SparcV9::g5, SparcV9::g6, SparcV9::g7, SparcV9::o6,
264      0
265   };
266   return CalleeSaveRegs;
267 }
268
269 } // end namespace llvm
270
271 //===----------------------------------------------------------------------===//
272 //
273 // The second section of this file (immediately following) contains the
274 // SparcV9 implementation of the MRegisterInfo class. It currently consists
275 // entirely of stub functions, because the SparcV9 target does not use the
276 // same register allocator that the X86 target uses.
277 //
278 //===----------------------------------------------------------------------===//
279
280 SparcV9RegisterInfo::SparcV9RegisterInfo ()
281   : MRegisterInfo (RegisterDescriptors, 104, RegisterClasses,
282                    RegisterClasses + 5) {
283 }
284
285 void SparcV9RegisterInfo::storeRegToStackSlot(MachineBasicBlock &MBB,
286                                          MachineBasicBlock::iterator MI,
287                                          unsigned SrcReg, int FrameIndex,
288                                          const TargetRegisterClass *RC) const {
289   abort ();
290 }
291
292 void SparcV9RegisterInfo::loadRegFromStackSlot(MachineBasicBlock &MBB,
293                                           MachineBasicBlock::iterator MI,
294                                           unsigned DestReg, int FrameIndex,
295                                           const TargetRegisterClass *RC) const {
296   abort ();
297 }
298
299 void SparcV9RegisterInfo::copyRegToReg(MachineBasicBlock &MBB,
300                                       MachineBasicBlock::iterator MI,
301                                       unsigned DestReg, unsigned SrcReg,
302                                       const TargetRegisterClass *RC) const {
303   abort ();
304 }
305
306 void SparcV9RegisterInfo::eliminateFrameIndex(MachineBasicBlock::iterator MI)
307   const {
308   abort ();
309 }
310
311 void SparcV9RegisterInfo::emitPrologue(MachineFunction &MF) const {
312   abort ();
313 }
314
315 void SparcV9RegisterInfo::emitEpilogue(MachineFunction &MF,
316                                        MachineBasicBlock &MBB) const {
317   abort ();
318 }
319
320
321 unsigned SparcV9RegisterInfo::getFrameRegister(MachineFunction &MF) const {
322   abort ();
323   return 0;
324 }