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"
30 SystemZRegisterInfo::SystemZRegisterInfo(SystemZTargetMachine &tm,
31 const SystemZInstrInfo &tii)
32 : SystemZGenRegisterInfo(SystemZ::ADJCALLSTACKUP, SystemZ::ADJCALLSTACKDOWN),
37 SystemZRegisterInfo::getCalleeSavedRegs(const MachineFunction *MF) const {
38 static const unsigned CalleeSavedRegs[] = {
39 SystemZ::R6D, SystemZ::R7D, SystemZ::R8D, SystemZ::R9D,
40 SystemZ::R10D, SystemZ::R11D, SystemZ::R12D, SystemZ::R13D,
41 SystemZ::R14D, SystemZ::R15D,
42 SystemZ::F8L, SystemZ::F9L, SystemZ::F10L, SystemZ::F11L,
43 SystemZ::F12L, SystemZ::F13L, SystemZ::F14L, SystemZ::F15L,
47 return CalleeSavedRegs;
50 BitVector SystemZRegisterInfo::getReservedRegs(const MachineFunction &MF) const {
51 BitVector Reserved(getNumRegs());
52 const TargetFrameLowering *TFI = MF.getTarget().getFrameLowering();
55 Reserved.set(SystemZ::R11D);
56 Reserved.set(SystemZ::R14D);
57 Reserved.set(SystemZ::R15D);
61 const TargetRegisterClass*
62 SystemZRegisterInfo::getMatchingSuperRegClass(const TargetRegisterClass *A,
63 const TargetRegisterClass *B,
66 // Exact sub-classes don't exist for the other sub-register indexes.
68 case SystemZ::subreg_32bit:
69 if (B == SystemZ::ADDR32RegisterClass)
70 return A->getSize() == 8 ? SystemZ::ADDR64RegisterClass : 0;
75 void SystemZRegisterInfo::
76 eliminateCallFramePseudoInstr(MachineFunction &MF, MachineBasicBlock &MBB,
77 MachineBasicBlock::iterator I) const {
82 SystemZRegisterInfo::eliminateFrameIndex(MachineBasicBlock::iterator II,
83 int SPAdj, RegScavenger *RS) const {
84 assert(SPAdj == 0 && "Unxpected");
87 MachineInstr &MI = *II;
88 MachineFunction &MF = *MI.getParent()->getParent();
89 const TargetFrameLowering *TFI = MF.getTarget().getFrameLowering();
91 while (!MI.getOperand(i).isFI()) {
93 assert(i < MI.getNumOperands() && "Instr doesn't have FrameIndex operand!");
96 int FrameIndex = MI.getOperand(i).getIndex();
98 unsigned BasePtr = (TFI->hasFP(MF) ? SystemZ::R11D : SystemZ::R15D);
100 // This must be part of a rri or ri operand memory reference. Replace the
101 // FrameIndex with base register with BasePtr. Add an offset to the
102 // displacement field.
103 MI.getOperand(i).ChangeToRegister(BasePtr, false);
105 // Offset is a either 12-bit unsigned or 20-bit signed integer.
106 // FIXME: handle "too long" displacements.
108 TFI->getFrameIndexOffset(MF, FrameIndex) + MI.getOperand(i+1).getImm();
110 // Check whether displacement is too long to fit into 12 bit zext field.
111 MI.setDesc(TII.getMemoryInstr(MI.getOpcode(), Offset));
113 MI.getOperand(i+1).ChangeToImmediate(Offset);
116 unsigned SystemZRegisterInfo::getRARegister() const {
117 assert(0 && "What is the return address register");
122 SystemZRegisterInfo::getFrameRegister(const MachineFunction &MF) const {
123 assert(0 && "What is the frame register");
127 unsigned SystemZRegisterInfo::getEHExceptionRegister() const {
128 assert(0 && "What is the exception register");
132 unsigned SystemZRegisterInfo::getEHHandlerRegister() const {
133 assert(0 && "What is the exception handler register");
137 int SystemZRegisterInfo::getDwarfRegNum(unsigned RegNum, bool isEH) const {
138 assert(0 && "What is the dwarf register number");
142 #include "SystemZGenRegisterInfo.inc"