LLVM  8.0.1
Mips16RegisterInfo.cpp
Go to the documentation of this file.
1 //===-- Mips16RegisterInfo.cpp - MIPS16 Register Information --------------===//
2 //
3 // The LLVM Compiler Infrastructure
4 //
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
7 //
8 //===----------------------------------------------------------------------===//
9 //
10 // This file contains the MIPS16 implementation of the TargetRegisterInfo class.
11 //
12 //===----------------------------------------------------------------------===//
13 
14 #include "Mips16RegisterInfo.h"
15 #include "Mips.h"
16 #include "Mips16InstrInfo.h"
17 #include "MipsInstrInfo.h"
18 #include "MipsMachineFunction.h"
19 #include "MipsSubtarget.h"
20 #include "llvm/ADT/STLExtras.h"
27 #include "llvm/IR/Constants.h"
28 #include "llvm/IR/DebugInfo.h"
29 #include "llvm/IR/Function.h"
30 #include "llvm/IR/Type.h"
31 #include "llvm/Support/Debug.h"
36 
37 using namespace llvm;
38 
39 #define DEBUG_TYPE "mips16-registerinfo"
40 
42 
44  (const MachineFunction &MF) const {
45  return false;
46 }
48  (const MachineFunction &MF) const {
49  return false;
50 }
51 
53  (const MachineFunction &MF) const {
54  return false;
55 }
56 
61  const TargetRegisterClass *RC,
62  unsigned Reg) const {
63  DebugLoc DL;
65  TII.copyPhysReg(MBB, I, DL, Mips::T0, Reg, true);
66  TII.copyPhysReg(MBB, UseMI, DL, Reg, Mips::T0, true);
67  return true;
68 }
69 
70 const TargetRegisterClass *
72  assert(Size == 4);
73  return &Mips::CPU16RegsRegClass;
74 }
75 
76 void Mips16RegisterInfo::eliminateFI(MachineBasicBlock::iterator II,
77  unsigned OpNo, int FrameIndex,
78  uint64_t StackSize,
79  int64_t SPOffset) const {
80  MachineInstr &MI = *II;
81  MachineFunction &MF = *MI.getParent()->getParent();
82  MachineFrameInfo &MFI = MF.getFrameInfo();
83 
84  const std::vector<CalleeSavedInfo> &CSI = MFI.getCalleeSavedInfo();
85  int MinCSFI = 0;
86  int MaxCSFI = -1;
87 
88  if (CSI.size()) {
89  MinCSFI = CSI[0].getFrameIdx();
90  MaxCSFI = CSI[CSI.size() - 1].getFrameIdx();
91  }
92 
93  // The following stack frame objects are always
94  // referenced relative to $sp:
95  // 1. Outgoing arguments.
96  // 2. Pointer to dynamically allocated stack space.
97  // 3. Locations for callee-saved registers.
98  // Everything else is referenced relative to whatever register
99  // getFrameRegister() returns.
100  unsigned FrameReg;
101 
102  if (FrameIndex >= MinCSFI && FrameIndex <= MaxCSFI)
103  FrameReg = Mips::SP;
104  else {
106  if (TFI->hasFP(MF)) {
107  FrameReg = Mips::S0;
108  }
109  else {
110  if ((MI.getNumOperands()> OpNo+2) && MI.getOperand(OpNo+2).isReg())
111  FrameReg = MI.getOperand(OpNo+2).getReg();
112  else
113  FrameReg = Mips::SP;
114  }
115  }
116  // Calculate final offset.
117  // - There is no need to change the offset if the frame object
118  // is one of the
119  // following: an outgoing argument, pointer to a dynamically allocated
120  // stack space or a $gp restore location,
121  // - If the frame object is any of the following,
122  // its offset must be adjusted
123  // by adding the size of the stack:
124  // incoming argument, callee-saved register location or local variable.
125  int64_t Offset;
126  bool IsKill = false;
127  Offset = SPOffset + (int64_t)StackSize;
128  Offset += MI.getOperand(OpNo + 1).getImm();
129 
130  LLVM_DEBUG(errs() << "Offset : " << Offset << "\n"
131  << "<--------->\n");
132 
133  if (!MI.isDebugValue() &&
135  MachineBasicBlock &MBB = *MI.getParent();
136  DebugLoc DL = II->getDebugLoc();
137  unsigned NewImm;
138  const Mips16InstrInfo &TII =
139  *static_cast<const Mips16InstrInfo *>(MF.getSubtarget().getInstrInfo());
140  FrameReg = TII.loadImmediate(FrameReg, Offset, MBB, II, DL, NewImm);
141  Offset = SignExtend64<16>(NewImm);
142  IsKill = true;
143  }
144  MI.getOperand(OpNo).ChangeToRegister(FrameReg, false, false, IsKill);
145  MI.getOperand(OpNo + 1).ChangeToImmediate(Offset);
146 
147 
148 }
raw_ostream & errs()
This returns a reference to a raw_ostream for standard error.
This class represents lattice values for constants.
Definition: AllocatorList.h:24
void ChangeToRegister(unsigned Reg, bool isDef, bool isImp=false, bool isKill=false, bool isDead=false, bool isUndef=false, bool isDebug=false)
ChangeToRegister - Replace this operand with a new register operand of the specified value...
bool useFPForScavengingIndex(const MachineFunction &MF) const override
bool requiresFrameIndexScavenging(const MachineFunction &MF) const override
unsigned getReg() const
getReg - Returns the register number.
unsigned Reg
A debug info location.
Definition: DebugLoc.h:34
bool saveScavengerRegister(MachineBasicBlock &MBB, MachineBasicBlock::iterator I, MachineBasicBlock::iterator &UseMI, const TargetRegisterClass *RC, unsigned Reg) const override
bool requiresRegisterScavenging(const MachineFunction &MF) const override
const HexagonInstrInfo * TII
unsigned getNumOperands() const
Retuns the total number of operands.
Definition: MachineInstr.h:412
virtual bool hasFP(const MachineFunction &MF) const =0
hasFP - Return true if the specified function should have a dedicated frame pointer register...
unsigned loadImmediate(unsigned FrameReg, int64_t Imm, MachineBasicBlock &MBB, MachineBasicBlock::iterator II, const DebugLoc &DL, unsigned &NewImm) const
Emit a series of instructions to load an immediate.
The MachineFrameInfo class represents an abstract stack frame until prolog/epilog code is inserted...
unsigned getOpcode() const
Returns the opcode of this MachineInstr.
Definition: MachineInstr.h:409
static bool validImmediate(unsigned Opcode, unsigned Reg, int64_t Amount)
virtual void copyPhysReg(MachineBasicBlock &MBB, MachineBasicBlock::iterator MI, const DebugLoc &DL, unsigned DestReg, unsigned SrcReg, bool KillSrc) const
Emit instructions to copy a pair of physical registers.
const TargetRegisterClass * intRegClass(unsigned Size) const override
Return GPR register class.
virtual const TargetInstrInfo * getInstrInfo() const
void ChangeToImmediate(int64_t ImmVal)
ChangeToImmediate - Replace this operand with a new immediate operand of the specified value...
TargetInstrInfo - Interface to description of machine instruction set.
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.
MachineInstrBuilder & UseMI
This file contains the declarations for the subclasses of Constant, which represent the different fla...
bool isDebugValue() const
Definition: MachineInstr.h:997
Information about stack frame layout on the target.
int64_t getImm() const
const MachineBasicBlock * getParent() const
Definition: MachineInstr.h:254
Representation of each machine instruction.
Definition: MachineInstr.h:64
const MachineFunction * getParent() const
Return the MachineFunction containing this basic block.
const std::vector< CalleeSavedInfo > & getCalleeSavedInfo() const
Returns a reference to call saved info vector for the current function.
#define I(x, y, z)
Definition: MD5.cpp:58
virtual const TargetFrameLowering * getFrameLowering() const
uint32_t Size
Definition: Profile.cpp:47
bool isReg() const
isReg - Tests if this is a MO_Register operand.
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
IRTranslator LLVM IR MI
#define LLVM_DEBUG(X)
Definition: Debug.h:123
const MachineOperand & getOperand(unsigned i) const
Definition: MachineInstr.h:414