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/Target/TargetFrameLowering.h"
25 #include "llvm/Target/TargetMachine.h"
26 #include "llvm/Target/TargetOptions.h"
27 #include "llvm/Target/TargetInstrInfo.h"
28 #include "llvm/Support/CommandLine.h"
29 #include "llvm/Support/Debug.h"
30 #include "llvm/Support/ErrorHandling.h"
31 #include "llvm/Support/raw_ostream.h"
32 #include "llvm/ADT/BitVector.h"
33 #include "llvm/ADT/STLExtras.h"
36 #define GET_REGINFO_TARGET_DESC
37 #include "AlphaGenRegisterInfo.inc"
41 AlphaRegisterInfo::AlphaRegisterInfo(const TargetInstrInfo &tii)
42 : AlphaGenRegisterInfo(Alpha::R26), TII(tii) {
45 static long getUpper16(long l) {
46 long y = l / Alpha::IMM_MULT;
47 if (l % Alpha::IMM_MULT > Alpha::IMM_HIGH)
52 static long getLower16(long l) {
53 long h = getUpper16(l);
54 return l - h * Alpha::IMM_MULT;
57 const unsigned* AlphaRegisterInfo::getCalleeSavedRegs(const MachineFunction *MF)
59 static const unsigned CalleeSavedRegs[] = {
60 Alpha::R9, Alpha::R10,
61 Alpha::R11, Alpha::R12,
62 Alpha::R13, Alpha::R14,
66 Alpha::F8, Alpha::F9, 0
68 return CalleeSavedRegs;
71 BitVector AlphaRegisterInfo::getReservedRegs(const MachineFunction &MF) const {
72 BitVector Reserved(getNumRegs());
73 Reserved.set(Alpha::R15);
74 Reserved.set(Alpha::R29);
75 Reserved.set(Alpha::R30);
76 Reserved.set(Alpha::R31);
80 //===----------------------------------------------------------------------===//
81 // Stack Frame Processing methods
82 //===----------------------------------------------------------------------===//
84 void AlphaRegisterInfo::
85 eliminateCallFramePseudoInstr(MachineFunction &MF, MachineBasicBlock &MBB,
86 MachineBasicBlock::iterator I) const {
87 const TargetFrameLowering *TFI = MF.getTarget().getFrameLowering();
90 // If we have a frame pointer, turn the adjcallstackup instruction into a
91 // 'sub ESP, <amt>' and the adjcallstackdown instruction into 'add ESP,
93 MachineInstr *Old = I;
94 uint64_t Amount = Old->getOperand(0).getImm();
96 // We need to keep the stack aligned properly. To do this, we round the
97 // amount of space needed for the outgoing arguments up to the next
98 // alignment boundary.
99 unsigned Align = TFI->getStackAlignment();
100 Amount = (Amount+Align-1)/Align*Align;
103 if (Old->getOpcode() == Alpha::ADJUSTSTACKDOWN) {
104 New=BuildMI(MF, Old->getDebugLoc(), TII.get(Alpha::LDA), Alpha::R30)
105 .addImm(-Amount).addReg(Alpha::R30);
107 assert(Old->getOpcode() == Alpha::ADJUSTSTACKUP);
108 New=BuildMI(MF, Old->getDebugLoc(), TII.get(Alpha::LDA), Alpha::R30)
109 .addImm(Amount).addReg(Alpha::R30);
112 // Replace the pseudo instruction with a new instruction...
120 //Alpha has a slightly funny stack:
123 //fixed locals (and spills, callee saved, etc)
129 AlphaRegisterInfo::eliminateFrameIndex(MachineBasicBlock::iterator II,
130 int SPAdj, RegScavenger *RS) const {
131 assert(SPAdj == 0 && "Unexpected");
134 MachineInstr &MI = *II;
135 MachineBasicBlock &MBB = *MI.getParent();
136 MachineFunction &MF = *MBB.getParent();
137 const TargetFrameLowering *TFI = MF.getTarget().getFrameLowering();
139 bool FP = TFI->hasFP(MF);
141 while (!MI.getOperand(i).isFI()) {
143 assert(i < MI.getNumOperands() && "Instr doesn't have FrameIndex operand!");
146 int FrameIndex = MI.getOperand(i).getIndex();
148 // Add the base register of R30 (SP) or R15 (FP).
149 MI.getOperand(i + 1).ChangeToRegister(FP ? Alpha::R15 : Alpha::R30, false);
151 // Now add the frame object offset to the offset from the virtual frame index.
152 int Offset = MF.getFrameInfo()->getObjectOffset(FrameIndex);
154 DEBUG(errs() << "FI: " << FrameIndex << " Offset: " << Offset << "\n");
156 Offset += MF.getFrameInfo()->getStackSize();
158 DEBUG(errs() << "Corrected Offset " << Offset
159 << " for stack size: " << MF.getFrameInfo()->getStackSize() << "\n");
161 if (Offset > Alpha::IMM_HIGH || Offset < Alpha::IMM_LOW) {
162 DEBUG(errs() << "Unconditionally using R28 for evil purposes Offset: "
164 //so in this case, we need to use a temporary register, and move the
165 //original inst off the SP/FP
167 MI.getOperand(i + 1).ChangeToRegister(Alpha::R28, false);
168 MI.getOperand(i).ChangeToImmediate(getLower16(Offset));
170 MachineInstr* nMI=BuildMI(MF, MI.getDebugLoc(),
171 TII.get(Alpha::LDAH), Alpha::R28)
172 .addImm(getUpper16(Offset)).addReg(FP ? Alpha::R15 : Alpha::R30);
175 MI.getOperand(i).ChangeToImmediate(Offset);
179 unsigned AlphaRegisterInfo::getFrameRegister(const MachineFunction &MF) const {
180 const TargetFrameLowering *TFI = MF.getTarget().getFrameLowering();
182 return TFI->hasFP(MF) ? Alpha::R15 : Alpha::R30;
185 unsigned AlphaRegisterInfo::getEHExceptionRegister() const {
186 llvm_unreachable("What is the exception register");
190 unsigned AlphaRegisterInfo::getEHHandlerRegister() const {
191 llvm_unreachable("What is the exception handler register");
195 std::string AlphaRegisterInfo::getPrettyName(unsigned reg)
197 std::string s(AlphaRegDesc[reg].Name);