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(),
48 static long getUpper16(long l
) {
49 long y
= l
/ Alpha::IMM_MULT
;
50 if (l
% Alpha::IMM_MULT
> Alpha::IMM_HIGH
)
55 static long getLower16(long l
) {
56 long h
= getUpper16(l
);
57 return l
- h
* Alpha::IMM_MULT
;
60 const unsigned* AlphaRegisterInfo::getCalleeSavedRegs(const MachineFunction
*MF
)
62 static const unsigned CalleeSavedRegs
[] = {
63 Alpha::R9
, Alpha::R10
,
64 Alpha::R11
, Alpha::R12
,
65 Alpha::R13
, Alpha::R14
,
69 Alpha::F8
, Alpha::F9
, 0
71 return CalleeSavedRegs
;
74 BitVector
AlphaRegisterInfo::getReservedRegs(const MachineFunction
&MF
) const {
75 BitVector
Reserved(getNumRegs());
76 Reserved
.set(Alpha::R15
);
77 Reserved
.set(Alpha::R29
);
78 Reserved
.set(Alpha::R30
);
79 Reserved
.set(Alpha::R31
);
83 //===----------------------------------------------------------------------===//
84 // Stack Frame Processing methods
85 //===----------------------------------------------------------------------===//
87 void AlphaRegisterInfo::
88 eliminateCallFramePseudoInstr(MachineFunction
&MF
, MachineBasicBlock
&MBB
,
89 MachineBasicBlock::iterator I
) const {
90 const TargetFrameLowering
*TFI
= MF
.getTarget().getFrameLowering();
93 // If we have a frame pointer, turn the adjcallstackup instruction into a
94 // 'sub ESP, <amt>' and the adjcallstackdown instruction into 'add ESP,
96 MachineInstr
*Old
= I
;
97 uint64_t Amount
= Old
->getOperand(0).getImm();
99 // We need to keep the stack aligned properly. To do this, we round the
100 // amount of space needed for the outgoing arguments up to the next
101 // alignment boundary.
102 unsigned Align
= TFI
->getStackAlignment();
103 Amount
= (Amount
+Align
-1)/Align
*Align
;
106 if (Old
->getOpcode() == Alpha::ADJUSTSTACKDOWN
) {
107 New
=BuildMI(MF
, Old
->getDebugLoc(), TII
.get(Alpha::LDA
), Alpha::R30
)
108 .addImm(-Amount
).addReg(Alpha::R30
);
110 assert(Old
->getOpcode() == Alpha::ADJUSTSTACKUP
);
111 New
=BuildMI(MF
, Old
->getDebugLoc(), TII
.get(Alpha::LDA
), Alpha::R30
)
112 .addImm(Amount
).addReg(Alpha::R30
);
115 // Replace the pseudo instruction with a new instruction...
123 //Alpha has a slightly funny stack:
126 //fixed locals (and spills, callee saved, etc)
132 AlphaRegisterInfo::eliminateFrameIndex(MachineBasicBlock::iterator II
,
133 int SPAdj
, RegScavenger
*RS
) const {
134 assert(SPAdj
== 0 && "Unexpected");
137 MachineInstr
&MI
= *II
;
138 MachineBasicBlock
&MBB
= *MI
.getParent();
139 MachineFunction
&MF
= *MBB
.getParent();
140 const TargetFrameLowering
*TFI
= MF
.getTarget().getFrameLowering();
142 bool FP
= TFI
->hasFP(MF
);
144 while (!MI
.getOperand(i
).isFI()) {
146 assert(i
< MI
.getNumOperands() && "Instr doesn't have FrameIndex operand!");
149 int FrameIndex
= MI
.getOperand(i
).getIndex();
151 // Add the base register of R30 (SP) or R15 (FP).
152 MI
.getOperand(i
+ 1).ChangeToRegister(FP
? Alpha::R15
: Alpha::R30
, false);
154 // Now add the frame object offset to the offset from the virtual frame index.
155 int Offset
= MF
.getFrameInfo()->getObjectOffset(FrameIndex
);
157 DEBUG(errs() << "FI: " << FrameIndex
<< " Offset: " << Offset
<< "\n");
159 Offset
+= MF
.getFrameInfo()->getStackSize();
161 DEBUG(errs() << "Corrected Offset " << Offset
162 << " for stack size: " << MF
.getFrameInfo()->getStackSize() << "\n");
164 if (Offset
> Alpha::IMM_HIGH
|| Offset
< Alpha::IMM_LOW
) {
165 DEBUG(errs() << "Unconditionally using R28 for evil purposes Offset: "
167 //so in this case, we need to use a temporary register, and move the
168 //original inst off the SP/FP
170 MI
.getOperand(i
+ 1).ChangeToRegister(Alpha::R28
, false);
171 MI
.getOperand(i
).ChangeToImmediate(getLower16(Offset
));
173 MachineInstr
* nMI
=BuildMI(MF
, MI
.getDebugLoc(),
174 TII
.get(Alpha::LDAH
), Alpha::R28
)
175 .addImm(getUpper16(Offset
)).addReg(FP
? Alpha::R15
: Alpha::R30
);
178 MI
.getOperand(i
).ChangeToImmediate(Offset
);
182 unsigned AlphaRegisterInfo::getRARegister() const {
186 unsigned AlphaRegisterInfo::getFrameRegister(const MachineFunction
&MF
) const {
187 const TargetFrameLowering
*TFI
= MF
.getTarget().getFrameLowering();
189 return TFI
->hasFP(MF
) ? Alpha::R15
: Alpha::R30
;
192 unsigned AlphaRegisterInfo::getEHExceptionRegister() const {
193 llvm_unreachable("What is the exception register");
197 unsigned AlphaRegisterInfo::getEHHandlerRegister() const {
198 llvm_unreachable("What is the exception handler register");
202 int AlphaRegisterInfo::getDwarfRegNum(unsigned RegNum
, bool isEH
) const {
203 llvm_unreachable("What is the dwarf register number");
207 int AlphaRegisterInfo::getLLVMRegNum(unsigned DwarfRegNum
, bool isEH
) const {
208 llvm_unreachable("What is the dwarf register number");
212 std::string
AlphaRegisterInfo::getPrettyName(unsigned reg
)
214 std::string
s(AlphaRegDesc
[reg
].Name
);