1 //===- SystemZRegisterInfo.cpp - SystemZ Register Information -------*- C++ -*-===//
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 SystemZ implementation of the TargetRegisterInfo class.
12 //===----------------------------------------------------------------------===//
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"
29 #define GET_REGINFO_MC_DESC
30 #define GET_REGINFO_TARGET_DESC
31 #include "SystemZGenRegisterInfo.inc"
35 SystemZRegisterInfo::SystemZRegisterInfo(SystemZTargetMachine
&tm
,
36 const SystemZInstrInfo
&tii
)
37 : SystemZGenRegisterInfo(), TM(tm
), TII(tii
) {
41 SystemZRegisterInfo::getCalleeSavedRegs(const MachineFunction
*MF
) const {
42 static const unsigned CalleeSavedRegs
[] = {
43 SystemZ::R6D
, SystemZ::R7D
, SystemZ::R8D
, SystemZ::R9D
,
44 SystemZ::R10D
, SystemZ::R11D
, SystemZ::R12D
, SystemZ::R13D
,
45 SystemZ::R14D
, SystemZ::R15D
,
46 SystemZ::F8L
, SystemZ::F9L
, SystemZ::F10L
, SystemZ::F11L
,
47 SystemZ::F12L
, SystemZ::F13L
, SystemZ::F14L
, SystemZ::F15L
,
51 return CalleeSavedRegs
;
54 BitVector
SystemZRegisterInfo::getReservedRegs(const MachineFunction
&MF
) const {
55 BitVector
Reserved(getNumRegs());
56 const TargetFrameLowering
*TFI
= MF
.getTarget().getFrameLowering();
59 // R11D is the frame pointer. Reserve all aliases.
60 Reserved
.set(SystemZ::R11D
);
61 Reserved
.set(SystemZ::R11W
);
62 Reserved
.set(SystemZ::R10P
);
63 Reserved
.set(SystemZ::R10Q
);
66 Reserved
.set(SystemZ::R14D
);
67 Reserved
.set(SystemZ::R15D
);
68 Reserved
.set(SystemZ::R14W
);
69 Reserved
.set(SystemZ::R15W
);
70 Reserved
.set(SystemZ::R14P
);
71 Reserved
.set(SystemZ::R14Q
);
75 const TargetRegisterClass
*
76 SystemZRegisterInfo::getMatchingSuperRegClass(const TargetRegisterClass
*A
,
77 const TargetRegisterClass
*B
,
80 // Exact sub-classes don't exist for the other sub-register indexes.
82 case SystemZ::subreg_32bit
:
83 if (B
== SystemZ::ADDR32RegisterClass
)
84 return A
->getSize() == 8 ? SystemZ::ADDR64RegisterClass
: 0;
89 void SystemZRegisterInfo::
90 eliminateCallFramePseudoInstr(MachineFunction
&MF
, MachineBasicBlock
&MBB
,
91 MachineBasicBlock::iterator I
) const {
96 SystemZRegisterInfo::eliminateFrameIndex(MachineBasicBlock::iterator II
,
97 int SPAdj
, RegScavenger
*RS
) const {
98 assert(SPAdj
== 0 && "Unxpected");
101 MachineInstr
&MI
= *II
;
102 MachineFunction
&MF
= *MI
.getParent()->getParent();
103 const TargetFrameLowering
*TFI
= MF
.getTarget().getFrameLowering();
105 while (!MI
.getOperand(i
).isFI()) {
107 assert(i
< MI
.getNumOperands() && "Instr doesn't have FrameIndex operand!");
110 int FrameIndex
= MI
.getOperand(i
).getIndex();
112 unsigned BasePtr
= (TFI
->hasFP(MF
) ? SystemZ::R11D
: SystemZ::R15D
);
114 // This must be part of a rri or ri operand memory reference. Replace the
115 // FrameIndex with base register with BasePtr. Add an offset to the
116 // displacement field.
117 MI
.getOperand(i
).ChangeToRegister(BasePtr
, false);
119 // Offset is a either 12-bit unsigned or 20-bit signed integer.
120 // FIXME: handle "too long" displacements.
122 TFI
->getFrameIndexOffset(MF
, FrameIndex
) + MI
.getOperand(i
+1).getImm();
124 // Check whether displacement is too long to fit into 12 bit zext field.
125 MI
.setDesc(TII
.getMemoryInstr(MI
.getOpcode(), Offset
));
127 MI
.getOperand(i
+1).ChangeToImmediate(Offset
);
130 unsigned SystemZRegisterInfo::getRARegister() const {
131 assert(0 && "What is the return address register");
136 SystemZRegisterInfo::getFrameRegister(const MachineFunction
&MF
) const {
137 assert(0 && "What is the frame register");
141 unsigned SystemZRegisterInfo::getEHExceptionRegister() const {
142 assert(0 && "What is the exception register");
146 unsigned SystemZRegisterInfo::getEHHandlerRegister() const {
147 assert(0 && "What is the exception handler register");
151 int SystemZRegisterInfo::getDwarfRegNum(unsigned RegNum
, bool isEH
) const {
152 assert(0 && "What is the dwarf register number");
156 int SystemZRegisterInfo::getLLVMRegNum(unsigned DwarfRegNo
, bool isEH
) const {
157 assert(0 && "What is the dwarf register number");