1 //===- AlphaRegisterInfo.cpp - Alpha 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 Alpha implementation of the TargetRegisterInfo class.
12 //===----------------------------------------------------------------------===//
14 #define DEBUG_TYPE "reginfo"
16 #include "AlphaRegisterInfo.h"
17 #include "llvm/Constants.h"
18 #include "llvm/Type.h"
19 #include "llvm/Function.h"
20 #include "llvm/CodeGen/ValueTypes.h"
21 #include "llvm/CodeGen/MachineInstrBuilder.h"
22 #include "llvm/CodeGen/MachineFunction.h"
23 #include "llvm/CodeGen/MachineFrameInfo.h"
24 #include "llvm/CodeGen/MachineLocation.h"
25 #include "llvm/Target/TargetFrameLowering.h"
26 #include "llvm/Target/TargetMachine.h"
27 #include "llvm/Target/TargetOptions.h"
28 #include "llvm/Target/TargetInstrInfo.h"
29 #include "llvm/Support/CommandLine.h"
30 #include "llvm/Support/Debug.h"
31 #include "llvm/Support/ErrorHandling.h"
32 #include "llvm/Support/raw_ostream.h"
33 #include "llvm/ADT/BitVector.h"
34 #include "llvm/ADT/STLExtras.h"
37 #define GET_REGINFO_MC_DESC
38 #define GET_REGINFO_TARGET_DESC
39 #include "AlphaGenRegisterInfo.inc"
43 AlphaRegisterInfo::AlphaRegisterInfo(const TargetInstrInfo &tii)
44 : AlphaGenRegisterInfo(AlphaRegDesc, AlphaRegInfoDesc,
45 Alpha::ADJUSTSTACKDOWN, Alpha::ADJUSTSTACKUP),
49 static long getUpper16(long l) {
50 long y = l / Alpha::IMM_MULT;
51 if (l % Alpha::IMM_MULT > Alpha::IMM_HIGH)
56 static long getLower16(long l) {
57 long h = getUpper16(l);
58 return l - h * Alpha::IMM_MULT;
61 const unsigned* AlphaRegisterInfo::getCalleeSavedRegs(const MachineFunction *MF)
63 static const unsigned CalleeSavedRegs[] = {
64 Alpha::R9, Alpha::R10,
65 Alpha::R11, Alpha::R12,
66 Alpha::R13, Alpha::R14,
70 Alpha::F8, Alpha::F9, 0
72 return CalleeSavedRegs;
75 BitVector AlphaRegisterInfo::getReservedRegs(const MachineFunction &MF) const {
76 BitVector Reserved(getNumRegs());
77 Reserved.set(Alpha::R15);
78 Reserved.set(Alpha::R29);
79 Reserved.set(Alpha::R30);
80 Reserved.set(Alpha::R31);
84 //===----------------------------------------------------------------------===//
85 // Stack Frame Processing methods
86 //===----------------------------------------------------------------------===//
88 void AlphaRegisterInfo::
89 eliminateCallFramePseudoInstr(MachineFunction &MF, MachineBasicBlock &MBB,
90 MachineBasicBlock::iterator I) const {
91 const TargetFrameLowering *TFI = MF.getTarget().getFrameLowering();
94 // If we have a frame pointer, turn the adjcallstackup instruction into a
95 // 'sub ESP, <amt>' and the adjcallstackdown instruction into 'add ESP,
97 MachineInstr *Old = I;
98 uint64_t Amount = Old->getOperand(0).getImm();
100 // We need to keep the stack aligned properly. To do this, we round the
101 // amount of space needed for the outgoing arguments up to the next
102 // alignment boundary.
103 unsigned Align = TFI->getStackAlignment();
104 Amount = (Amount+Align-1)/Align*Align;
107 if (Old->getOpcode() == Alpha::ADJUSTSTACKDOWN) {
108 New=BuildMI(MF, Old->getDebugLoc(), TII.get(Alpha::LDA), Alpha::R30)
109 .addImm(-Amount).addReg(Alpha::R30);
111 assert(Old->getOpcode() == Alpha::ADJUSTSTACKUP);
112 New=BuildMI(MF, Old->getDebugLoc(), TII.get(Alpha::LDA), Alpha::R30)
113 .addImm(Amount).addReg(Alpha::R30);
116 // Replace the pseudo instruction with a new instruction...
124 //Alpha has a slightly funny stack:
127 //fixed locals (and spills, callee saved, etc)
133 AlphaRegisterInfo::eliminateFrameIndex(MachineBasicBlock::iterator II,
134 int SPAdj, RegScavenger *RS) const {
135 assert(SPAdj == 0 && "Unexpected");
138 MachineInstr &MI = *II;
139 MachineBasicBlock &MBB = *MI.getParent();
140 MachineFunction &MF = *MBB.getParent();
141 const TargetFrameLowering *TFI = MF.getTarget().getFrameLowering();
143 bool FP = TFI->hasFP(MF);
145 while (!MI.getOperand(i).isFI()) {
147 assert(i < MI.getNumOperands() && "Instr doesn't have FrameIndex operand!");
150 int FrameIndex = MI.getOperand(i).getIndex();
152 // Add the base register of R30 (SP) or R15 (FP).
153 MI.getOperand(i + 1).ChangeToRegister(FP ? Alpha::R15 : Alpha::R30, false);
155 // Now add the frame object offset to the offset from the virtual frame index.
156 int Offset = MF.getFrameInfo()->getObjectOffset(FrameIndex);
158 DEBUG(errs() << "FI: " << FrameIndex << " Offset: " << Offset << "\n");
160 Offset += MF.getFrameInfo()->getStackSize();
162 DEBUG(errs() << "Corrected Offset " << Offset
163 << " for stack size: " << MF.getFrameInfo()->getStackSize() << "\n");
165 if (Offset > Alpha::IMM_HIGH || Offset < Alpha::IMM_LOW) {
166 DEBUG(errs() << "Unconditionally using R28 for evil purposes Offset: "
168 //so in this case, we need to use a temporary register, and move the
169 //original inst off the SP/FP
171 MI.getOperand(i + 1).ChangeToRegister(Alpha::R28, false);
172 MI.getOperand(i).ChangeToImmediate(getLower16(Offset));
174 MachineInstr* nMI=BuildMI(MF, MI.getDebugLoc(),
175 TII.get(Alpha::LDAH), Alpha::R28)
176 .addImm(getUpper16(Offset)).addReg(FP ? Alpha::R15 : Alpha::R30);
179 MI.getOperand(i).ChangeToImmediate(Offset);
183 unsigned AlphaRegisterInfo::getRARegister() const {
187 unsigned AlphaRegisterInfo::getFrameRegister(const MachineFunction &MF) const {
188 const TargetFrameLowering *TFI = MF.getTarget().getFrameLowering();
190 return TFI->hasFP(MF) ? Alpha::R15 : Alpha::R30;
193 unsigned AlphaRegisterInfo::getEHExceptionRegister() const {
194 llvm_unreachable("What is the exception register");
198 unsigned AlphaRegisterInfo::getEHHandlerRegister() const {
199 llvm_unreachable("What is the exception handler register");
203 int AlphaRegisterInfo::getDwarfRegNum(unsigned RegNum, bool isEH) const {
204 llvm_unreachable("What is the dwarf register number");
208 int AlphaRegisterInfo::getLLVMRegNum(unsigned DwarfRegNum, bool isEH) const {
209 llvm_unreachable("What is the dwarf register number");
213 std::string AlphaRegisterInfo::getPrettyName(unsigned reg)
215 std::string s(AlphaRegDesc[reg].Name);