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_TARGET_DESC
30 #include "SystemZGenRegisterInfo.inc"
34 SystemZRegisterInfo::SystemZRegisterInfo(SystemZTargetMachine &tm,
35 const SystemZInstrInfo &tii)
36 : SystemZGenRegisterInfo(0), TM(tm), TII(tii) {
40 SystemZRegisterInfo::getCalleeSavedRegs(const MachineFunction *MF) const {
41 static const unsigned CalleeSavedRegs[] = {
42 SystemZ::R6D, SystemZ::R7D, SystemZ::R8D, SystemZ::R9D,
43 SystemZ::R10D, SystemZ::R11D, SystemZ::R12D, SystemZ::R13D,
44 SystemZ::R14D, SystemZ::R15D,
45 SystemZ::F8L, SystemZ::F9L, SystemZ::F10L, SystemZ::F11L,
46 SystemZ::F12L, SystemZ::F13L, SystemZ::F14L, SystemZ::F15L,
50 return CalleeSavedRegs;
53 BitVector SystemZRegisterInfo::getReservedRegs(const MachineFunction &MF) const {
54 BitVector Reserved(getNumRegs());
55 const TargetFrameLowering *TFI = MF.getTarget().getFrameLowering();
58 // R11D is the frame pointer. Reserve all aliases.
59 Reserved.set(SystemZ::R11D);
60 Reserved.set(SystemZ::R11W);
61 Reserved.set(SystemZ::R10P);
62 Reserved.set(SystemZ::R10Q);
65 Reserved.set(SystemZ::R14D);
66 Reserved.set(SystemZ::R15D);
67 Reserved.set(SystemZ::R14W);
68 Reserved.set(SystemZ::R15W);
69 Reserved.set(SystemZ::R14P);
70 Reserved.set(SystemZ::R14Q);
74 const TargetRegisterClass*
75 SystemZRegisterInfo::getMatchingSuperRegClass(const TargetRegisterClass *A,
76 const TargetRegisterClass *B,
79 // Exact sub-classes don't exist for the other sub-register indexes.
81 case SystemZ::subreg_32bit:
82 if (B == SystemZ::ADDR32RegisterClass)
83 return A->getSize() == 8 ? SystemZ::ADDR64RegisterClass : 0;
88 void SystemZRegisterInfo::
89 eliminateCallFramePseudoInstr(MachineFunction &MF, MachineBasicBlock &MBB,
90 MachineBasicBlock::iterator I) const {
95 SystemZRegisterInfo::eliminateFrameIndex(MachineBasicBlock::iterator II,
96 int SPAdj, RegScavenger *RS) const {
97 assert(SPAdj == 0 && "Unxpected");
100 MachineInstr &MI = *II;
101 MachineFunction &MF = *MI.getParent()->getParent();
102 const TargetFrameLowering *TFI = MF.getTarget().getFrameLowering();
104 while (!MI.getOperand(i).isFI()) {
106 assert(i < MI.getNumOperands() && "Instr doesn't have FrameIndex operand!");
109 int FrameIndex = MI.getOperand(i).getIndex();
111 unsigned BasePtr = (TFI->hasFP(MF) ? SystemZ::R11D : SystemZ::R15D);
113 // This must be part of a rri or ri operand memory reference. Replace the
114 // FrameIndex with base register with BasePtr. Add an offset to the
115 // displacement field.
116 MI.getOperand(i).ChangeToRegister(BasePtr, false);
118 // Offset is a either 12-bit unsigned or 20-bit signed integer.
119 // FIXME: handle "too long" displacements.
121 TFI->getFrameIndexOffset(MF, FrameIndex) + MI.getOperand(i+1).getImm();
123 // Check whether displacement is too long to fit into 12 bit zext field.
124 MI.setDesc(TII.getMemoryInstr(MI.getOpcode(), Offset));
126 MI.getOperand(i+1).ChangeToImmediate(Offset);
130 SystemZRegisterInfo::getFrameRegister(const MachineFunction &MF) const {
131 assert(0 && "What is the frame register");
135 unsigned SystemZRegisterInfo::getEHExceptionRegister() const {
136 assert(0 && "What is the exception register");
140 unsigned SystemZRegisterInfo::getEHHandlerRegister() const {
141 assert(0 && "What is the exception handler register");