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/TargetFrameInfo.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());
53 Reserved.set(SystemZ::R11D);
54 Reserved.set(SystemZ::R14D);
55 Reserved.set(SystemZ::R15D);
59 /// needsFP - Return true if the specified function should have a dedicated
60 /// frame pointer register. This is true if the function has variable sized
61 /// allocas or if frame pointer elimination is disabled.
62 bool SystemZRegisterInfo::hasFP(const MachineFunction &MF) const {
63 const MachineFrameInfo *MFI = MF.getFrameInfo();
64 return DisableFramePointerElim(MF) || MFI->hasVarSizedObjects();
67 void SystemZRegisterInfo::
68 eliminateCallFramePseudoInstr(MachineFunction &MF, MachineBasicBlock &MBB,
69 MachineBasicBlock::iterator I) const {
73 int SystemZRegisterInfo::getFrameIndexOffset(const MachineFunction &MF,
75 const TargetFrameInfo &TFI = *MF.getTarget().getFrameInfo();
76 const MachineFrameInfo *MFI = MF.getFrameInfo();
77 const SystemZMachineFunctionInfo *SystemZMFI =
78 MF.getInfo<SystemZMachineFunctionInfo>();
79 int Offset = MFI->getObjectOffset(FI) + MFI->getOffsetAdjustment();
80 uint64_t StackSize = MFI->getStackSize();
82 // Fixed objects are really located in the "previous" frame.
84 StackSize -= SystemZMFI->getCalleeSavedFrameSize();
86 Offset += StackSize - TFI.getOffsetOfLocalArea();
88 // Skip the register save area if we generated the stack frame.
89 if (StackSize || MFI->hasCalls())
90 Offset -= TFI.getOffsetOfLocalArea();
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 while (!MI.getOperand(i).isFI()) {
105 assert(i < MI.getNumOperands() && "Instr doesn't have FrameIndex operand!");
108 int FrameIndex = MI.getOperand(i).getIndex();
110 unsigned BasePtr = (hasFP(MF) ? SystemZ::R11D : SystemZ::R15D);
112 // This must be part of a rri or ri operand memory reference. Replace the
113 // FrameIndex with base register with BasePtr. Add an offset to the
114 // displacement field.
115 MI.getOperand(i).ChangeToRegister(BasePtr, false);
117 // Offset is a either 12-bit unsigned or 20-bit signed integer.
118 // FIXME: handle "too long" displacements.
120 getFrameIndexOffset(MF, FrameIndex) + MI.getOperand(i+1).getImm();
122 // Check whether displacement is too long to fit into 12 bit zext field.
123 MI.setDesc(TII.getMemoryInstr(MI.getOpcode(), Offset));
125 MI.getOperand(i+1).ChangeToImmediate(Offset);
129 SystemZRegisterInfo::processFunctionBeforeCalleeSavedScan(MachineFunction &MF,
130 RegScavenger *RS) const {
131 // Determine whether R15/R14 will ever be clobbered inside the function. And
132 // if yes - mark it as 'callee' saved.
133 MachineFrameInfo *FFI = MF.getFrameInfo();
134 MachineRegisterInfo &MRI = MF.getRegInfo();
136 // Check whether high FPRs are ever used, if yes - we need to save R15 as
138 static const unsigned HighFPRs[] = {
139 SystemZ::F8L, SystemZ::F9L, SystemZ::F10L, SystemZ::F11L,
140 SystemZ::F12L, SystemZ::F13L, SystemZ::F14L, SystemZ::F15L,
141 SystemZ::F8S, SystemZ::F9S, SystemZ::F10S, SystemZ::F11S,
142 SystemZ::F12S, SystemZ::F13S, SystemZ::F14S, SystemZ::F15S,
145 bool HighFPRsUsed = false;
146 for (unsigned i = 0, e = array_lengthof(HighFPRs); i != e; ++i)
147 HighFPRsUsed |= MRI.isPhysRegUsed(HighFPRs[i]);
150 /* FIXME: function is varargs */
151 /* FIXME: function grabs RA */
152 /* FIXME: function calls eh_return */
153 MRI.setPhysRegUsed(SystemZ::R14D);
157 FFI->getObjectIndexEnd() != 0 || // Contains automatic variables
158 FFI->hasVarSizedObjects() // Function calls dynamic alloca's
159 /* FIXME: function is varargs */)
160 MRI.setPhysRegUsed(SystemZ::R15D);
163 unsigned SystemZRegisterInfo::getRARegister() const {
164 assert(0 && "What is the return address register");
169 SystemZRegisterInfo::getFrameRegister(const MachineFunction &MF) const {
170 assert(0 && "What is the frame register");
174 unsigned SystemZRegisterInfo::getEHExceptionRegister() const {
175 assert(0 && "What is the exception register");
179 unsigned SystemZRegisterInfo::getEHHandlerRegister() const {
180 assert(0 && "What is the exception handler register");
184 int SystemZRegisterInfo::getDwarfRegNum(unsigned RegNum, bool isEH) const {
185 assert(0 && "What is the dwarf register number");
189 #include "SystemZGenRegisterInfo.inc"