Hide more details in tablegen generated MCRegisterInfo ctor function.
[oota-llvm.git] / lib / Target / SystemZ / SystemZRegisterInfo.cpp
1 //===- SystemZRegisterInfo.cpp - SystemZ Register Information -------*- C++ -*-===//
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 SystemZ implementation of the TargetRegisterInfo class.
11 //
12 //===----------------------------------------------------------------------===//
13
14 #include "SystemZ.h"
15 #include "SystemZInstrInfo.h"
16 #include "SystemZMachineFunctionInfo.h"
17 #include "SystemZRegisterInfo.h"
18 #include "SystemZSubtarget.h"
19 #include "llvm/CodeGen/MachineInstrBuilder.h"
20 #include "llvm/CodeGen/MachineFrameInfo.h"
21 #include "llvm/CodeGen/MachineFunction.h"
22 #include "llvm/CodeGen/MachineRegisterInfo.h"
23 #include "llvm/Target/TargetFrameLowering.h"
24 #include "llvm/Target/TargetInstrInfo.h"
25 #include "llvm/Target/TargetMachine.h"
26 #include "llvm/Target/TargetOptions.h"
27 #include "llvm/ADT/BitVector.h"
28
29 #define GET_REGINFO_MC_DESC
30 #define GET_REGINFO_TARGET_DESC
31 #include "SystemZGenRegisterInfo.inc"
32
33 using namespace llvm;
34
35 SystemZRegisterInfo::SystemZRegisterInfo(SystemZTargetMachine &tm,
36                                          const SystemZInstrInfo &tii)
37   : SystemZGenRegisterInfo(SystemZ::ADJCALLSTACKUP, SystemZ::ADJCALLSTACKDOWN),
38     TM(tm), TII(tii) {
39 }
40
41 const unsigned*
42 SystemZRegisterInfo::getCalleeSavedRegs(const MachineFunction *MF) const {
43   static const unsigned CalleeSavedRegs[] = {
44     SystemZ::R6D,  SystemZ::R7D,  SystemZ::R8D,  SystemZ::R9D,
45     SystemZ::R10D, SystemZ::R11D, SystemZ::R12D, SystemZ::R13D,
46     SystemZ::R14D, SystemZ::R15D,
47     SystemZ::F8L,  SystemZ::F9L,  SystemZ::F10L, SystemZ::F11L,
48     SystemZ::F12L, SystemZ::F13L, SystemZ::F14L, SystemZ::F15L,
49     0
50   };
51
52   return CalleeSavedRegs;
53 }
54
55 BitVector SystemZRegisterInfo::getReservedRegs(const MachineFunction &MF) const {
56   BitVector Reserved(getNumRegs());
57   const TargetFrameLowering *TFI = MF.getTarget().getFrameLowering();
58
59   if (TFI->hasFP(MF)) {
60     // R11D is the frame pointer. Reserve all aliases.
61     Reserved.set(SystemZ::R11D);
62     Reserved.set(SystemZ::R11W);
63     Reserved.set(SystemZ::R10P);
64     Reserved.set(SystemZ::R10Q);
65   }
66
67   Reserved.set(SystemZ::R14D);
68   Reserved.set(SystemZ::R15D);
69   Reserved.set(SystemZ::R14W);
70   Reserved.set(SystemZ::R15W);
71   Reserved.set(SystemZ::R14P);
72   Reserved.set(SystemZ::R14Q);
73   return Reserved;
74 }
75
76 const TargetRegisterClass*
77 SystemZRegisterInfo::getMatchingSuperRegClass(const TargetRegisterClass *A,
78                                               const TargetRegisterClass *B,
79                                               unsigned Idx) const {
80   switch(Idx) {
81   // Exact sub-classes don't exist for the other sub-register indexes.
82   default: return 0;
83   case SystemZ::subreg_32bit:
84     if (B == SystemZ::ADDR32RegisterClass)
85       return A->getSize() == 8 ? SystemZ::ADDR64RegisterClass : 0;
86     return A;
87   }
88 }
89
90 void SystemZRegisterInfo::
91 eliminateCallFramePseudoInstr(MachineFunction &MF, MachineBasicBlock &MBB,
92                               MachineBasicBlock::iterator I) const {
93   MBB.erase(I);
94 }
95
96 void
97 SystemZRegisterInfo::eliminateFrameIndex(MachineBasicBlock::iterator II,
98                                          int SPAdj, RegScavenger *RS) const {
99   assert(SPAdj == 0 && "Unxpected");
100
101   unsigned i = 0;
102   MachineInstr &MI = *II;
103   MachineFunction &MF = *MI.getParent()->getParent();
104   const TargetFrameLowering *TFI = MF.getTarget().getFrameLowering();
105
106   while (!MI.getOperand(i).isFI()) {
107     ++i;
108     assert(i < MI.getNumOperands() && "Instr doesn't have FrameIndex operand!");
109   }
110
111   int FrameIndex = MI.getOperand(i).getIndex();
112
113   unsigned BasePtr = (TFI->hasFP(MF) ? SystemZ::R11D : SystemZ::R15D);
114
115   // This must be part of a rri or ri operand memory reference.  Replace the
116   // FrameIndex with base register with BasePtr.  Add an offset to the
117   // displacement field.
118   MI.getOperand(i).ChangeToRegister(BasePtr, false);
119
120   // Offset is a either 12-bit unsigned or 20-bit signed integer.
121   // FIXME: handle "too long" displacements.
122   int Offset =
123     TFI->getFrameIndexOffset(MF, FrameIndex) + MI.getOperand(i+1).getImm();
124
125   // Check whether displacement is too long to fit into 12 bit zext field.
126   MI.setDesc(TII.getMemoryInstr(MI.getOpcode(), Offset));
127
128   MI.getOperand(i+1).ChangeToImmediate(Offset);
129 }
130
131 unsigned SystemZRegisterInfo::getRARegister() const {
132   assert(0 && "What is the return address register");
133   return 0;
134 }
135
136 unsigned
137 SystemZRegisterInfo::getFrameRegister(const MachineFunction &MF) const {
138   assert(0 && "What is the frame register");
139   return 0;
140 }
141
142 unsigned SystemZRegisterInfo::getEHExceptionRegister() const {
143   assert(0 && "What is the exception register");
144   return 0;
145 }
146
147 unsigned SystemZRegisterInfo::getEHHandlerRegister() const {
148   assert(0 && "What is the exception handler register");
149   return 0;
150 }
151
152 int SystemZRegisterInfo::getDwarfRegNum(unsigned RegNum, bool isEH) const {
153   assert(0 && "What is the dwarf register number");
154   return -1;
155 }
156
157 int SystemZRegisterInfo::getLLVMRegNum(unsigned DwarfRegNo, bool isEH) const {
158   assert(0 && "What is the dwarf register number");
159   return -1;
160 }