LLVM 24.0.0git
Mips16RegisterInfo.cpp
Go to the documentation of this file.
1//===-- Mips16RegisterInfo.cpp - MIPS16 Register Information --------------===//
2//
3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6//
7//===----------------------------------------------------------------------===//
8//
9// This file contains the MIPS16 implementation of the TargetRegisterInfo class.
10//
11//===----------------------------------------------------------------------===//
12
13#include "Mips16RegisterInfo.h"
14#include "Mips16InstrInfo.h"
15#include "MipsInstrInfo.h"
20#include "llvm/IR/Function.h"
21#include "llvm/IR/Type.h"
22#include "llvm/Support/Debug.h"
26
27using namespace llvm;
28
29#define DEBUG_TYPE "mips16-registerinfo"
30
32 (const MachineFunction &MF) const {
33 return false;
34}
36 (const MachineFunction &MF) const {
37 return false;
38}
39
41 (const MachineFunction &MF) const {
42 return false;
43}
44
48 Register Reg) const {
50 const TargetInstrInfo &TII = *MBB.getParent()->getSubtarget().getInstrInfo();
51 TII.copyPhysReg(MBB, I, DL, Mips::R8, Reg, true);
52 TII.copyPhysReg(MBB, UseMI, DL, Reg, Mips::R8, true);
53 return true;
54}
55
58 assert(Size == 4);
59 return &Mips::CPU16RegsRegClass;
60}
61
62void Mips16RegisterInfo::eliminateFI(MachineBasicBlock::iterator II,
63 unsigned OpNo, int FrameIndex,
64 uint64_t StackSize,
65 int64_t SPOffset) const {
66 MachineInstr &MI = *II;
67 MachineFunction &MF = *MI.getParent()->getParent();
69
70 const std::vector<CalleeSavedInfo> &CSI = MFI.getCalleeSavedInfo();
71 int MinCSFI = 0;
72 int MaxCSFI = -1;
73
74 if (CSI.size()) {
75 MinCSFI = CSI[0].getFrameIdx();
76 MaxCSFI = CSI[CSI.size() - 1].getFrameIdx();
77 }
78
79 // The following stack frame objects are always
80 // referenced relative to $sp:
81 // 1. Outgoing arguments.
82 // 2. Pointer to dynamically allocated stack space.
83 // 3. Locations for callee-saved registers.
84 // Everything else is referenced relative to whatever register
85 // getFrameRegister() returns.
86 Register FrameReg;
87
88 if (FrameIndex >= MinCSFI && FrameIndex <= MaxCSFI)
89 FrameReg = Mips::SP;
90 else {
92 if (TFI->hasFP(MF)) {
93 FrameReg = Mips::R16;
94 }
95 else {
96 if ((MI.getNumOperands()> OpNo+2) && MI.getOperand(OpNo+2).isReg())
97 FrameReg = MI.getOperand(OpNo+2).getReg();
98 else
99 FrameReg = Mips::SP;
100 }
101 }
102 // Calculate final offset.
103 // - There is no need to change the offset if the frame object
104 // is one of the
105 // following: an outgoing argument, pointer to a dynamically allocated
106 // stack space or a $gp restore location,
107 // - If the frame object is any of the following,
108 // its offset must be adjusted
109 // by adding the size of the stack:
110 // incoming argument, callee-saved register location or local variable.
111 int64_t Offset;
112 bool IsKill = false;
113 Offset = SPOffset + (int64_t)StackSize;
114 Offset += MI.getOperand(OpNo + 1).getImm();
115
116 LLVM_DEBUG(errs() << "Offset : " << Offset << "\n"
117 << "<--------->\n");
118
119 if (!MI.isDebugValue() &&
120 !Mips16InstrInfo::validImmediate(MI.getOpcode(), FrameReg, Offset)) {
121 MachineBasicBlock &MBB = *MI.getParent();
122 DebugLoc DL = II->getDebugLoc();
123 unsigned NewImm;
124 const Mips16InstrInfo &TII =
125 *static_cast<const Mips16InstrInfo *>(MF.getSubtarget().getInstrInfo());
126 FrameReg = TII.loadImmediate(FrameReg, Offset, MBB, II, DL, NewImm);
127 Offset = SignExtend64<16>(NewImm);
128 IsKill = true;
129 }
130 MI.getOperand(OpNo).ChangeToRegister(FrameReg, false, false, IsKill);
131 MI.getOperand(OpNo + 1).ChangeToImmediate(Offset);
132
133
134}
MachineInstrBuilder & UseMI
assert(UImm &&(UImm !=~static_cast< T >(0)) &&"Invalid immediate!")
const AArch64InstrInfo & TII
MachineBasicBlock & MBB
MachineBasicBlock MachineBasicBlock::iterator DebugLoc DL
IRTranslator LLVM IR MI
#define I(x, y, z)
Definition MD5.cpp:57
uint64_t IntrinsicInst * II
#define LLVM_DEBUG(...)
Definition Debug.h:119
A debug info location.
Definition DebugLoc.h:126
const MachineFunction * getParent() const
Return the MachineFunction containing this basic block.
MachineInstrBundleIterator< MachineInstr > iterator
The MachineFrameInfo class represents an abstract stack frame until prolog/epilog code is inserted.
const std::vector< CalleeSavedInfo > & getCalleeSavedInfo() const
Returns a reference to call saved info vector for the current function.
const TargetSubtargetInfo & getSubtarget() const
getSubtarget - Return the subtarget for which this machine code is being compiled.
MachineFrameInfo & getFrameInfo()
getFrameInfo - Return the frame info object for the current function.
Representation of each machine instruction.
static bool validImmediate(unsigned Opcode, unsigned Reg, int64_t Amount)
bool requiresFrameIndexScavenging(const MachineFunction &MF) const override
bool useFPForScavengingIndex(const MachineFunction &MF) const override
bool saveScavengerRegister(MachineBasicBlock &MBB, MachineBasicBlock::iterator I, MachineBasicBlock::iterator &UseMI, const TargetRegisterClass *RC, Register Reg) const override
const TargetRegisterClass * intRegClass(unsigned Size) const override
Return GPR register class.
bool requiresRegisterScavenging(const MachineFunction &MF) const override
Wrapper class representing virtual and physical registers.
Definition Register.h:20
Information about stack frame layout on the target.
bool hasFP(const MachineFunction &MF) const
hasFP - Return true if the specified function should have a dedicated frame pointer register.
TargetInstrInfo - Interface to description of machine instruction set.
virtual const TargetFrameLowering * getFrameLowering() const
constexpr MCPhysReg SP
This is an optimization pass for GlobalISel generic memory operations.
@ Offset
Definition DWP.cpp:577
LLVM_ABI raw_fd_ostream & errs()
This returns a reference to a raw_ostream for standard error.
constexpr int64_t SignExtend64(uint64_t x)
Sign-extend the number in the bottom B bits of X to a 64-bit integer.
Definition MathExtras.h:572
MCRegisterClass TargetRegisterClass
Definition FastISel.h:58