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 const Mips16InstrInfo &I)
43 : MipsRegisterInfo(ST), TII(I) {}
45 // This function eliminate ADJCALLSTACKDOWN,
46 // ADJCALLSTACKUP pseudo instructions
47 void Mips16RegisterInfo::
48 eliminateCallFramePseudoInstr(MachineFunction &MF, MachineBasicBlock &MBB,
49 MachineBasicBlock::iterator I) const {
50 // Simply discard ADJCALLSTACKDOWN, ADJCALLSTACKUP instructions.
54 void Mips16RegisterInfo::eliminateFI(MachineBasicBlock::iterator II,
55 unsigned OpNo, int FrameIndex,
57 int64_t SPOffset) const {
58 MachineInstr &MI = *II;
59 MachineFunction &MF = *MI.getParent()->getParent();
60 MachineFrameInfo *MFI = MF.getFrameInfo();
61 MipsFunctionInfo *MipsFI = MF.getInfo<MipsFunctionInfo>();
63 const std::vector<CalleeSavedInfo> &CSI = MFI->getCalleeSavedInfo();
68 MinCSFI = CSI[0].getFrameIdx();
69 MaxCSFI = CSI[CSI.size() - 1].getFrameIdx();
72 // The following stack frame objects are always
73 // referenced relative to $sp:
74 // 1. Outgoing arguments.
75 // 2. Pointer to dynamically allocated stack space.
76 // 3. Locations for callee-saved registers.
77 // Everything else is referenced relative to whatever register
78 // getFrameRegister() returns.
81 if (MipsFI->isOutArgFI(FrameIndex) ||
82 (FrameIndex >= MinCSFI && FrameIndex <= MaxCSFI))
83 FrameReg = Subtarget.isABI_N64() ? Mips::SP_64 : Mips::SP;
85 FrameReg = getFrameRegister(MF);
87 // Calculate final offset.
88 // - There is no need to change the offset if the frame object
90 // following: an outgoing argument, pointer to a dynamically allocated
91 // stack space or a $gp restore location,
92 // - If the frame object is any of the following,
93 // its offset must be adjusted
94 // by adding the size of the stack:
95 // incoming argument, callee-saved register location or local variable.
98 if (MipsFI->isOutArgFI(FrameIndex))
101 Offset = SPOffset + (int64_t)StackSize;
103 Offset += MI.getOperand(OpNo + 1).getImm();
105 DEBUG(errs() << "Offset : " << Offset << "\n" << "<--------->\n");
107 MI.getOperand(OpNo).ChangeToRegister(FrameReg, false);
108 MI.getOperand(OpNo + 1).ChangeToImmediate(Offset);