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"
16 #include "MipsAnalyzeImmediate.h"
17 #include "MipsInstrInfo.h"
18 #include "MipsSubtarget.h"
19 #include "MipsMachineFunction.h"
20 #include "llvm/Constants.h"
21 #include "llvm/DebugInfo.h"
22 #include "llvm/Type.h"
23 #include "llvm/Function.h"
24 #include "llvm/CodeGen/ValueTypes.h"
25 #include "llvm/CodeGen/MachineInstrBuilder.h"
26 #include "llvm/CodeGen/MachineFunction.h"
27 #include "llvm/CodeGen/MachineFrameInfo.h"
28 #include "llvm/Target/TargetFrameLowering.h"
29 #include "llvm/Target/TargetMachine.h"
30 #include "llvm/Target/TargetOptions.h"
31 #include "llvm/Target/TargetInstrInfo.h"
32 #include "llvm/Support/CommandLine.h"
33 #include "llvm/Support/Debug.h"
34 #include "llvm/Support/ErrorHandling.h"
35 #include "llvm/Support/raw_ostream.h"
36 #include "llvm/ADT/BitVector.h"
37 #include "llvm/ADT/STLExtras.h"
41 Mips16RegisterInfo::Mips16RegisterInfo(const MipsSubtarget &ST)
42 : MipsRegisterInfo(ST) {}
44 // This function eliminate ADJCALLSTACKDOWN,
45 // ADJCALLSTACKUP pseudo instructions
46 void Mips16RegisterInfo::
47 eliminateCallFramePseudoInstr(MachineFunction &MF, MachineBasicBlock &MBB,
48 MachineBasicBlock::iterator I) const {
49 // Simply discard ADJCALLSTACKDOWN, ADJCALLSTACKUP instructions.
53 void Mips16RegisterInfo::eliminateFI(MachineBasicBlock::iterator II,
54 unsigned OpNo, int FrameIndex,
56 int64_t SPOffset) const {
57 MachineInstr &MI = *II;
58 MachineFunction &MF = *MI.getParent()->getParent();
59 MachineFrameInfo *MFI = MF.getFrameInfo();
61 const std::vector<CalleeSavedInfo> &CSI = MFI->getCalleeSavedInfo();
66 MinCSFI = CSI[0].getFrameIdx();
67 MaxCSFI = CSI[CSI.size() - 1].getFrameIdx();
70 // The following stack frame objects are always
71 // referenced relative to $sp:
72 // 1. Outgoing arguments.
73 // 2. Pointer to dynamically allocated stack space.
74 // 3. Locations for callee-saved registers.
75 // Everything else is referenced relative to whatever register
76 // getFrameRegister() returns.
79 if (FrameIndex >= MinCSFI && FrameIndex <= MaxCSFI)
82 const TargetFrameLowering *TFI = MF.getTarget().getFrameLowering();
87 if ((MI.getNumOperands()> OpNo+2) && MI.getOperand(OpNo+2).isReg())
88 FrameReg = MI.getOperand(OpNo+2).getReg();
93 // Calculate final offset.
94 // - There is no need to change the offset if the frame object
96 // following: an outgoing argument, pointer to a dynamically allocated
97 // stack space or a $gp restore location,
98 // - If the frame object is any of the following,
99 // its offset must be adjusted
100 // by adding the size of the stack:
101 // incoming argument, callee-saved register location or local variable.
103 Offset = SPOffset + (int64_t)StackSize;
104 Offset += MI.getOperand(OpNo + 1).getImm();
107 DEBUG(errs() << "Offset : " << Offset << "\n" << "<--------->\n");
109 MI.getOperand(OpNo).ChangeToRegister(FrameReg, false);
110 MI.getOperand(OpNo + 1).ChangeToImmediate(Offset);