Path: blob/main/contrib/llvm-project/llvm/lib/Target/Mips/Mips16RegisterInfo.cpp
96353 views
//===-- Mips16RegisterInfo.cpp - MIPS16 Register Information --------------===//1//2// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.3// See https://llvm.org/LICENSE.txt for license information.4// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception5//6//===----------------------------------------------------------------------===//7//8// This file contains the MIPS16 implementation of the TargetRegisterInfo class.9//10//===----------------------------------------------------------------------===//1112#include "Mips16RegisterInfo.h"13#include "Mips.h"14#include "Mips16InstrInfo.h"15#include "MipsInstrInfo.h"16#include "MipsMachineFunction.h"17#include "MipsSubtarget.h"18#include "llvm/ADT/STLExtras.h"19#include "llvm/CodeGen/MachineFrameInfo.h"20#include "llvm/CodeGen/MachineFunction.h"21#include "llvm/CodeGen/MachineInstrBuilder.h"22#include "llvm/CodeGen/MachineRegisterInfo.h"23#include "llvm/CodeGen/TargetFrameLowering.h"24#include "llvm/CodeGen/TargetInstrInfo.h"25#include "llvm/IR/Constants.h"26#include "llvm/IR/DebugInfo.h"27#include "llvm/IR/Function.h"28#include "llvm/IR/Type.h"29#include "llvm/Support/Debug.h"30#include "llvm/Support/ErrorHandling.h"31#include "llvm/Support/raw_ostream.h"32#include "llvm/Target/TargetMachine.h"33#include "llvm/Target/TargetOptions.h"3435using namespace llvm;3637#define DEBUG_TYPE "mips16-registerinfo"3839Mips16RegisterInfo::Mips16RegisterInfo() = default;4041bool Mips16RegisterInfo::requiresRegisterScavenging42(const MachineFunction &MF) const {43return false;44}45bool Mips16RegisterInfo::requiresFrameIndexScavenging46(const MachineFunction &MF) const {47return false;48}4950bool Mips16RegisterInfo::useFPForScavengingIndex51(const MachineFunction &MF) const {52return false;53}5455bool Mips16RegisterInfo::saveScavengerRegister(56MachineBasicBlock &MBB, MachineBasicBlock::iterator I,57MachineBasicBlock::iterator &UseMI, const TargetRegisterClass *RC,58Register Reg) const {59DebugLoc DL;60const TargetInstrInfo &TII = *MBB.getParent()->getSubtarget().getInstrInfo();61TII.copyPhysReg(MBB, I, DL, Mips::T0, Reg, true);62TII.copyPhysReg(MBB, UseMI, DL, Reg, Mips::T0, true);63return true;64}6566const TargetRegisterClass *67Mips16RegisterInfo::intRegClass(unsigned Size) const {68assert(Size == 4);69return &Mips::CPU16RegsRegClass;70}7172void Mips16RegisterInfo::eliminateFI(MachineBasicBlock::iterator II,73unsigned OpNo, int FrameIndex,74uint64_t StackSize,75int64_t SPOffset) const {76MachineInstr &MI = *II;77MachineFunction &MF = *MI.getParent()->getParent();78MachineFrameInfo &MFI = MF.getFrameInfo();7980const std::vector<CalleeSavedInfo> &CSI = MFI.getCalleeSavedInfo();81int MinCSFI = 0;82int MaxCSFI = -1;8384if (CSI.size()) {85MinCSFI = CSI[0].getFrameIdx();86MaxCSFI = CSI[CSI.size() - 1].getFrameIdx();87}8889// The following stack frame objects are always90// referenced relative to $sp:91// 1. Outgoing arguments.92// 2. Pointer to dynamically allocated stack space.93// 3. Locations for callee-saved registers.94// Everything else is referenced relative to whatever register95// getFrameRegister() returns.96Register FrameReg;9798if (FrameIndex >= MinCSFI && FrameIndex <= MaxCSFI)99FrameReg = Mips::SP;100else {101const TargetFrameLowering *TFI = MF.getSubtarget().getFrameLowering();102if (TFI->hasFP(MF)) {103FrameReg = Mips::S0;104}105else {106if ((MI.getNumOperands()> OpNo+2) && MI.getOperand(OpNo+2).isReg())107FrameReg = MI.getOperand(OpNo+2).getReg();108else109FrameReg = Mips::SP;110}111}112// Calculate final offset.113// - There is no need to change the offset if the frame object114// is one of the115// following: an outgoing argument, pointer to a dynamically allocated116// stack space or a $gp restore location,117// - If the frame object is any of the following,118// its offset must be adjusted119// by adding the size of the stack:120// incoming argument, callee-saved register location or local variable.121int64_t Offset;122bool IsKill = false;123Offset = SPOffset + (int64_t)StackSize;124Offset += MI.getOperand(OpNo + 1).getImm();125126LLVM_DEBUG(errs() << "Offset : " << Offset << "\n"127<< "<--------->\n");128129if (!MI.isDebugValue() &&130!Mips16InstrInfo::validImmediate(MI.getOpcode(), FrameReg, Offset)) {131MachineBasicBlock &MBB = *MI.getParent();132DebugLoc DL = II->getDebugLoc();133unsigned NewImm;134const Mips16InstrInfo &TII =135*static_cast<const Mips16InstrInfo *>(MF.getSubtarget().getInstrInfo());136FrameReg = TII.loadImmediate(FrameReg, Offset, MBB, II, DL, NewImm);137Offset = SignExtend64<16>(NewImm);138IsKill = true;139}140MI.getOperand(OpNo).ChangeToRegister(FrameReg, false, false, IsKill);141MI.getOperand(OpNo + 1).ChangeToImmediate(Offset);142143144}145146147