1 //===-- Mips16RegisterInfo.cpp - MIPS16 Register Information -== ----------===//
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 MIPS16 implementation of the TargetRegisterInfo class.
12 //===----------------------------------------------------------------------===//
14 #include "Mips16RegisterInfo.h"
15 #include "Mips16InstrInfo.h"
17 #include "MipsAnalyzeImmediate.h"
18 #include "MipsInstrInfo.h"
19 #include "MipsSubtarget.h"
20 #include "MipsMachineFunction.h"
21 #include "llvm/Constants.h"
22 #include "llvm/DebugInfo.h"
23 #include "llvm/Type.h"
24 #include "llvm/Function.h"
25 #include "llvm/CodeGen/ValueTypes.h"
26 #include "llvm/CodeGen/MachineInstrBuilder.h"
27 #include "llvm/CodeGen/MachineFunction.h"
28 #include "llvm/CodeGen/MachineFrameInfo.h"
29 #include "llvm/Target/TargetFrameLowering.h"
30 #include "llvm/Target/TargetMachine.h"
31 #include "llvm/Target/TargetOptions.h"
32 #include "llvm/Target/TargetInstrInfo.h"
33 #include "llvm/Support/CommandLine.h"
34 #include "llvm/Support/Debug.h"
35 #include "llvm/Support/ErrorHandling.h"
36 #include "llvm/Support/raw_ostream.h"
37 #include "llvm/ADT/BitVector.h"
38 #include "llvm/ADT/STLExtras.h"
42 Mips16RegisterInfo::Mips16RegisterInfo(const MipsSubtarget &ST,
43 const Mips16InstrInfo &I)
44 : MipsRegisterInfo(ST), TII(I) {}
46 // This function eliminate ADJCALLSTACKDOWN,
47 // ADJCALLSTACKUP pseudo instructions
48 void Mips16RegisterInfo::
49 eliminateCallFramePseudoInstr(MachineFunction &MF, MachineBasicBlock &MBB,
50 MachineBasicBlock::iterator I) const {
51 const TargetFrameLowering *TFI = MF.getTarget().getFrameLowering();
53 if (!TFI->hasReservedCallFrame(MF)) {
54 int64_t Amount = I->getOperand(0).getImm();
56 if (I->getOpcode() == Mips::ADJCALLSTACKDOWN)
59 const Mips16InstrInfo *II = static_cast<const Mips16InstrInfo*>(&TII);
61 II->adjustStackPtr(Mips::SP, Amount, MBB, I);
67 void Mips16RegisterInfo::eliminateFI(MachineBasicBlock::iterator II,
68 unsigned OpNo, int FrameIndex,
70 int64_t SPOffset) const {
71 MachineInstr &MI = *II;
72 MachineFunction &MF = *MI.getParent()->getParent();
73 MachineFrameInfo *MFI = MF.getFrameInfo();
75 const std::vector<CalleeSavedInfo> &CSI = MFI->getCalleeSavedInfo();
80 MinCSFI = CSI[0].getFrameIdx();
81 MaxCSFI = CSI[CSI.size() - 1].getFrameIdx();
84 // The following stack frame objects are always
85 // referenced relative to $sp:
86 // 1. Outgoing arguments.
87 // 2. Pointer to dynamically allocated stack space.
88 // 3. Locations for callee-saved registers.
89 // Everything else is referenced relative to whatever register
90 // getFrameRegister() returns.
93 if (FrameIndex >= MinCSFI && FrameIndex <= MaxCSFI)
96 const TargetFrameLowering *TFI = MF.getTarget().getFrameLowering();
101 if ((MI.getNumOperands()> OpNo+2) && MI.getOperand(OpNo+2).isReg())
102 FrameReg = MI.getOperand(OpNo+2).getReg();
107 // Calculate final offset.
108 // - There is no need to change the offset if the frame object
110 // following: an outgoing argument, pointer to a dynamically allocated
111 // stack space or a $gp restore location,
112 // - If the frame object is any of the following,
113 // its offset must be adjusted
114 // by adding the size of the stack:
115 // incoming argument, callee-saved register location or local variable.
117 Offset = SPOffset + (int64_t)StackSize;
118 Offset += MI.getOperand(OpNo + 1).getImm();
121 DEBUG(errs() << "Offset : " << Offset << "\n" << "<--------->\n");
123 MI.getOperand(OpNo).ChangeToRegister(FrameReg, false);
124 MI.getOperand(OpNo + 1).ChangeToImmediate(Offset);